blob: 13a649a2b6af99a4058001103b104e651fad2f59 [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
Derek Sollenbergereece0dd2014-02-27 14:31:29 -050026#include <SkBitmap.h>
Jason Samsffe9f482009-06-01 17:45:53 -070027
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080028#include <androidfw/Asset.h>
29#include <androidfw/AssetManager.h>
30#include <androidfw/ResourceTypes.h>
Jason Samsf29ca502009-06-23 12:22:47 -070031
Jason Samsd19f10d2009-05-22 14:03:28 -070032#include "jni.h"
33#include "JNIHelp.h"
34#include "android_runtime/AndroidRuntime.h"
Jim Milleree956052010-08-19 18:56:00 -070035#include "android_runtime/android_view_Surface.h"
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -080036#include "android_runtime/android_util_AssetManager.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070037
Jason Sams1d6983a2012-02-16 16:07:49 -080038#include <rs.h>
39#include <rsEnv.h>
Jason Samsfb9aa9f2012-03-28 15:30:07 -070040#include <gui/Surface.h>
Andy McFaddend47f7d82012-12-18 09:48:38 -080041#include <gui/GLConsumer.h>
Mathias Agopian52800612013-02-14 17:11:20 -080042#include <gui/Surface.h>
Jason Samsfaa32b32011-06-20 16:58:04 -070043#include <android_runtime/android_graphics_SurfaceTexture.h>
Jason Samsd19f10d2009-05-22 14:03:28 -070044
Steve Block3762c312012-01-06 19:20:56 +000045//#define LOG_API ALOGE
Jason Samsd19f10d2009-05-22 14:03:28 -070046#define LOG_API(...)
47
48using namespace android;
49
Stephen Hines414fa2c2014-04-17 01:02:42 -070050#define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \
Jason Samse729a942013-11-06 11:22:02 -080051 jint len = 0; \
52 void *ptr = NULL; \
Jason Sams21659ac2013-11-06 15:08:07 -080053 size_t typeBytes = 0; \
Stephen Hines414fa2c2014-04-17 01:02:42 -070054 jint relFlag = 0; \
55 if (readonly) { \
56 /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \
57 relFlag = JNI_ABORT; \
58 } \
Jason Samse729a942013-11-06 11:22:02 -080059 switch(dataType) { \
60 case RS_TYPE_FLOAT_32: \
61 len = _env->GetArrayLength((jfloatArray)data); \
62 ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080063 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080064 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070065 _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080066 return; \
67 case RS_TYPE_FLOAT_64: \
68 len = _env->GetArrayLength((jdoubleArray)data); \
69 ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080070 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -080071 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070072 _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080073 return; \
74 case RS_TYPE_SIGNED_8: \
75 case RS_TYPE_UNSIGNED_8: \
76 len = _env->GetArrayLength((jbyteArray)data); \
77 ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080078 typeBytes = 1; \
Jason Samse729a942013-11-06 11:22:02 -080079 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070080 _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080081 return; \
82 case RS_TYPE_SIGNED_16: \
83 case RS_TYPE_UNSIGNED_16: \
84 len = _env->GetArrayLength((jshortArray)data); \
85 ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080086 typeBytes = 2; \
Jason Samse729a942013-11-06 11:22:02 -080087 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070088 _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080089 return; \
90 case RS_TYPE_SIGNED_32: \
91 case RS_TYPE_UNSIGNED_32: \
92 len = _env->GetArrayLength((jintArray)data); \
93 ptr = _env->GetIntArrayElements((jintArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -080094 typeBytes = 4; \
Jason Samse729a942013-11-06 11:22:02 -080095 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -070096 _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -080097 return; \
98 case RS_TYPE_SIGNED_64: \
99 case RS_TYPE_UNSIGNED_64: \
100 len = _env->GetArrayLength((jlongArray)data); \
101 ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
Jason Sams21659ac2013-11-06 15:08:07 -0800102 typeBytes = 8; \
Jason Samse729a942013-11-06 11:22:02 -0800103 fnc(__VA_ARGS__); \
Stephen Hines414fa2c2014-04-17 01:02:42 -0700104 _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
Jason Samse729a942013-11-06 11:22:02 -0800105 return; \
106 default: \
107 break; \
108 } \
109}
110
111
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800112class AutoJavaStringToUTF8 {
113public:
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800114 AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800115 fCStr = env->GetStringUTFChars(str, NULL);
116 fLength = env->GetStringUTFLength(str);
117 }
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800118 ~AutoJavaStringToUTF8() {
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800119 fEnv->ReleaseStringUTFChars(fJStr, fCStr);
120 }
121 const char* c_str() const { return fCStr; }
122 jsize length() const { return fLength; }
123
124private:
125 JNIEnv* fEnv;
126 jstring fJStr;
127 const char* fCStr;
128 jsize fLength;
129};
130
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800131class AutoJavaStringArrayToUTF8 {
132public:
133 AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
134 : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
135 mCStrings = NULL;
136 mSizeArray = NULL;
137 if (stringsLength > 0) {
138 mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
139 mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
140 for (jsize ct = 0; ct < stringsLength; ct ++) {
141 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
142 mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL);
143 mSizeArray[ct] = mEnv->GetStringUTFLength(s);
144 }
145 }
146 }
147 ~AutoJavaStringArrayToUTF8() {
148 for (jsize ct=0; ct < mStringsLength; ct++) {
149 jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
150 mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
151 }
152 free(mCStrings);
153 free(mSizeArray);
154 }
155 const char **c_str() const { return mCStrings; }
156 size_t *c_str_len() const { return mSizeArray; }
157 jsize length() const { return mStringsLength; }
158
159private:
160 JNIEnv *mEnv;
161 jobjectArray mStrings;
162 const char **mCStrings;
163 size_t *mSizeArray;
164 jsize mStringsLength;
165};
166
Jason Samsd19f10d2009-05-22 14:03:28 -0700167// ---------------------------------------------------------------------------
168
Jason Samsffe9f482009-06-01 17:45:53 -0700169static jfieldID gContextId = 0;
170static jfieldID gNativeBitmapID = 0;
Jason Sams43ee06852009-08-12 17:54:11 -0700171static jfieldID gTypeNativeCache = 0;
Jason Samsd19f10d2009-05-22 14:03:28 -0700172
173static void _nInit(JNIEnv *_env, jclass _this)
174{
Tim Murrayeff663f2013-11-15 13:08:30 -0800175 gContextId = _env->GetFieldID(_this, "mContext", "J");
Jason Samsffe9f482009-06-01 17:45:53 -0700176
177 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000178 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
Jason Samsd19f10d2009-05-22 14:03:28 -0700179}
180
Jason Samsd19f10d2009-05-22 14:03:28 -0700181// ---------------------------------------------------------------------------
182
Jason Sams3eaa338e2009-06-10 15:04:38 -0700183static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800184nContextFinish(JNIEnv *_env, jobject _this, jlong con)
Jason Sams96ed4cf2010-06-15 12:15:57 -0700185{
Tim Murray71a01b82014-01-07 15:36:19 -0800186 LOG_API("nContextFinish, con(%p)", (RsContext)con);
Tim Murrayeff663f2013-11-15 13:08:30 -0800187 rsContextFinish((RsContext)con);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700188}
189
190static void
Tim Murray460a0492013-11-19 12:45:54 -0800191nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str)
Jason Sams3eaa338e2009-06-10 15:04:38 -0700192{
Tim Murray71a01b82014-01-07 15:36:19 -0800193 LOG_API("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700194 jint len = _env->GetArrayLength(str);
195 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0);
Tim Murrayeff663f2013-11-15 13:08:30 -0800196 rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len);
Jason Sams3eaa338e2009-06-10 15:04:38 -0700197 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT);
198}
199
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700200static jstring
Tim Murray460a0492013-11-19 12:45:54 -0800201nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700202{
Tim Murray71a01b82014-01-07 15:36:19 -0800203 LOG_API("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj);
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700204 const char *name = NULL;
Tim Murrayeff663f2013-11-15 13:08:30 -0800205 rsaGetName((RsContext)con, (void *)obj, &name);
Alex Sakhartchouk581cc642010-10-27 14:10:07 -0700206 if(name == NULL || strlen(name) == 0) {
207 return NULL;
208 }
Alex Sakhartchoukfb10c162010-08-04 14:45:48 -0700209 return _env->NewStringUTF(name);
210}
211
Jason Sams7ce033d2009-08-18 14:14:24 -0700212static void
Tim Murray460a0492013-11-19 12:45:54 -0800213nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj)
Jason Sams7ce033d2009-08-18 14:14:24 -0700214{
Tim Murray71a01b82014-01-07 15:36:19 -0800215 LOG_API("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj);
Tim Murrayeff663f2013-11-15 13:08:30 -0800216 rsObjDestroy((RsContext)con, (void *)obj);
Jason Sams7ce033d2009-08-18 14:14:24 -0700217}
218
Jason Sams3eaa338e2009-06-10 15:04:38 -0700219// ---------------------------------------------------------------------------
220
Tim Murrayeff663f2013-11-15 13:08:30 -0800221static jlong
Jason Samsd19f10d2009-05-22 14:03:28 -0700222nDeviceCreate(JNIEnv *_env, jobject _this)
223{
224 LOG_API("nDeviceCreate");
Tim Murray3aa89c12014-08-18 17:51:22 -0700225 return (jlong)(uintptr_t)rsDeviceCreate();
Jason Samsd19f10d2009-05-22 14:03:28 -0700226}
227
228static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800229nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev)
Jason Samsd19f10d2009-05-22 14:03:28 -0700230{
231 LOG_API("nDeviceDestroy");
232 return rsDeviceDestroy((RsDevice)dev);
233}
234
Jason Samsebfb4362009-09-23 13:57:02 -0700235static void
Tim Murray5eaf4682014-01-10 11:25:52 -0800236nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value)
Jason Samsebfb4362009-09-23 13:57:02 -0700237{
238 LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value);
239 return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
240}
241
Tim Murrayeff663f2013-11-15 13:08:30 -0800242static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800243nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer, jint ct)
Jason Samsd19f10d2009-05-22 14:03:28 -0700244{
245 LOG_API("nContextCreate");
Tim Murray3aa89c12014-08-18 17:51:22 -0700246 return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, 0);
Jason Sams704ff642010-02-09 16:05:07 -0800247}
248
Tim Murrayeff663f2013-11-15 13:08:30 -0800249static jlong
Tim Murray5eaf4682014-01-10 11:25:52 -0800250nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000251 jint colorMin, jint colorPref,
252 jint alphaMin, jint alphaPref,
253 jint depthMin, jint depthPref,
254 jint stencilMin, jint stencilPref,
255 jint samplesMin, jint samplesPref, jfloat samplesQ,
256 jint dpi)
Jason Sams704ff642010-02-09 16:05:07 -0800257{
Jason Sams11c8af92010-10-13 15:31:10 -0700258 RsSurfaceConfig sc;
259 sc.alphaMin = alphaMin;
260 sc.alphaPref = alphaPref;
261 sc.colorMin = colorMin;
262 sc.colorPref = colorPref;
263 sc.depthMin = depthMin;
264 sc.depthPref = depthPref;
265 sc.samplesMin = samplesMin;
266 sc.samplesPref = samplesPref;
267 sc.samplesQ = samplesQ;
268
Jason Sams704ff642010-02-09 16:05:07 -0800269 LOG_API("nContextCreateGL");
Tim Murray3aa89c12014-08-18 17:51:22 -0700270 return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi);
Jason Samsd19f10d2009-05-22 14:03:28 -0700271}
272
273static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800274nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p)
Jason Sams7d787b42009-11-15 12:14:26 -0800275{
Tim Murray71a01b82014-01-07 15:36:19 -0800276 LOG_API("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p);
Tim Murrayeff663f2013-11-15 13:08:30 -0800277 rsContextSetPriority((RsContext)con, p);
Jason Sams7d787b42009-11-15 12:14:26 -0800278}
279
280
281
282static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800283nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd)
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800284{
Tim Murray71a01b82014-01-07 15:36:19 -0800285 LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con, width, height, (Surface *)wnd);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800286
Alex Sakhartchouk6c72eec2011-05-17 12:32:47 -0700287 ANativeWindow * window = NULL;
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800288 if (wnd == NULL) {
289
290 } else {
Jeff Brown64a55af2012-08-26 02:47:39 -0700291 window = android_view_Surface_getNativeWindow(_env, wnd).get();
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800292 }
293
Tim Murrayeff663f2013-11-15 13:08:30 -0800294 rsContextSetSurface((RsContext)con, width, height, window);
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800295}
296
297static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800298nContextDestroy(JNIEnv *_env, jobject _this, jlong con)
Jason Samsd19f10d2009-05-22 14:03:28 -0700299{
Tim Murray71a01b82014-01-07 15:36:19 -0800300 LOG_API("nContextDestroy, con(%p)", (RsContext)con);
Tim Murrayeff663f2013-11-15 13:08:30 -0800301 rsContextDestroy((RsContext)con);
Jason Samsd19f10d2009-05-22 14:03:28 -0700302}
303
Jason Sams715333b2009-11-17 17:26:46 -0800304static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800305nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits)
Jason Sams715333b2009-11-17 17:26:46 -0800306{
Jason Sams715333b2009-11-17 17:26:46 -0800307 LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits);
308 rsContextDump((RsContext)con, bits);
309}
Jason Samsd19f10d2009-05-22 14:03:28 -0700310
311static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800312nContextPause(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700313{
Tim Murray71a01b82014-01-07 15:36:19 -0800314 LOG_API("nContextPause, con(%p)", (RsContext)con);
Tim Murrayeff663f2013-11-15 13:08:30 -0800315 rsContextPause((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700316}
317
318static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800319nContextResume(JNIEnv *_env, jobject _this, jlong con)
Jason Sams65e7aa52009-09-24 17:38:20 -0700320{
Tim Murray71a01b82014-01-07 15:36:19 -0800321 LOG_API("nContextResume, con(%p)", (RsContext)con);
Tim Murrayeff663f2013-11-15 13:08:30 -0800322 rsContextResume((RsContext)con);
Jason Sams65e7aa52009-09-24 17:38:20 -0700323}
324
Jason Sams1c415172010-11-08 17:06:46 -0800325
326static jstring
Tim Murrayeff663f2013-11-15 13:08:30 -0800327nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con)
Jason Sams1c415172010-11-08 17:06:46 -0800328{
Tim Murray71a01b82014-01-07 15:36:19 -0800329 LOG_API("nContextGetErrorMessage, con(%p)", (RsContext)con);
Jason Sams1c415172010-11-08 17:06:46 -0800330 char buf[1024];
331
332 size_t receiveLen;
333 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800334 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700335 buf, sizeof(buf),
336 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700337 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800338 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100339 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams1c415172010-11-08 17:06:46 -0800340 }
341 return _env->NewStringUTF(buf);
342}
343
Jason Samsedbfabd2011-05-17 15:01:29 -0700344static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800345nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data)
Jason Sams516c3192009-10-06 13:58:47 -0700346{
Jason Sams516c3192009-10-06 13:58:47 -0700347 jint len = _env->GetArrayLength(data);
Tim Murray71a01b82014-01-07 15:36:19 -0800348 LOG_API("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len);
Jason Sams516c3192009-10-06 13:58:47 -0700349 jint *ptr = _env->GetIntArrayElements(data, NULL);
350 size_t receiveLen;
Jason Sams1c415172010-11-08 17:06:46 -0800351 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800352 int id = rsContextGetMessage((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700353 ptr, len * 4,
354 &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700355 &subID, sizeof(subID));
Jason Sams516c3192009-10-06 13:58:47 -0700356 if (!id && receiveLen) {
Steve Block71f2cf12011-10-20 11:56:00 +0100357 ALOGV("message receive buffer too small. %i", receiveLen);
Jason Sams516c3192009-10-06 13:58:47 -0700358 }
359 _env->ReleaseIntArrayElements(data, ptr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000360 return (jint)id;
Jason Sams1c415172010-11-08 17:06:46 -0800361}
362
363static jint
Tim Murrayeff663f2013-11-15 13:08:30 -0800364nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData)
Jason Sams1c415172010-11-08 17:06:46 -0800365{
Tim Murray71a01b82014-01-07 15:36:19 -0800366 LOG_API("nContextPeekMessage, con(%p)", (RsContext)con);
Jason Sams1c415172010-11-08 17:06:46 -0800367 jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
368 size_t receiveLen;
369 uint32_t subID;
Tim Murrayeff663f2013-11-15 13:08:30 -0800370 int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen),
Jason Samsedbfabd2011-05-17 15:01:29 -0700371 &subID, sizeof(subID));
Jason Sams1c415172010-11-08 17:06:46 -0800372 auxDataPtr[0] = (jint)subID;
373 auxDataPtr[1] = (jint)receiveLen;
374 _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000375 return (jint)id;
Jason Sams516c3192009-10-06 13:58:47 -0700376}
377
Tim Murrayeff663f2013-11-15 13:08:30 -0800378static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700379{
Tim Murray71a01b82014-01-07 15:36:19 -0800380 LOG_API("nContextInitToClient, con(%p)", (RsContext)con);
Tim Murrayeff663f2013-11-15 13:08:30 -0800381 rsContextInitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700382}
383
Tim Murrayeff663f2013-11-15 13:08:30 -0800384static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con)
Jason Sams516c3192009-10-06 13:58:47 -0700385{
Tim Murray71a01b82014-01-07 15:36:19 -0800386 LOG_API("nContextDeinitToClient, con(%p)", (RsContext)con);
Tim Murrayeff663f2013-11-15 13:08:30 -0800387 rsContextDeinitToClient((RsContext)con);
Jason Sams516c3192009-10-06 13:58:47 -0700388}
389
Jason Sams455d6442013-02-05 19:20:18 -0800390static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800391nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data)
Jason Sams455d6442013-02-05 19:20:18 -0800392{
393 jint *ptr = NULL;
394 jint len = 0;
395 if (data) {
396 len = _env->GetArrayLength(data);
Stephen Hinesa0eabfb2013-12-18 16:21:30 -0800397 ptr = _env->GetIntArrayElements(data, NULL);
Jason Sams455d6442013-02-05 19:20:18 -0800398 }
Tim Murray71a01b82014-01-07 15:36:19 -0800399 LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len);
Tim Murrayeff663f2013-11-15 13:08:30 -0800400 rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int));
Jason Sams455d6442013-02-05 19:20:18 -0800401 if (data) {
402 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
403 }
404}
405
406
Jason Sams516c3192009-10-06 13:58:47 -0700407
Tim Murray460a0492013-11-19 12:45:54 -0800408static jlong
409nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm, jint size)
Jason Samsd19f10d2009-05-22 14:03:28 -0700410{
Tim Murray71a01b82014-01-07 15:36:19 -0800411 LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", (RsContext)con, type, kind, norm, size);
Tim Murray3aa89c12014-08-18 17:51:22 -0700412 return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind, norm, size);
Jason Samsd19f10d2009-05-22 14:03:28 -0700413}
414
Tim Murray460a0492013-11-19 12:45:54 -0800415static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800416nElementCreate2(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat98071552014-02-12 09:54:43 +0000417 jlongArray _ids, jobjectArray _names, jintArray _arraySizes)
Jason Samsd19f10d2009-05-22 14:03:28 -0700418{
Jason Sams718cd1f2009-12-23 14:35:29 -0800419 int fieldCount = _env->GetArrayLength(_ids);
Tim Murray71a01b82014-01-07 15:36:19 -0800420 LOG_API("nElementCreate2, con(%p)", (RsContext)con);
Jason Sams718cd1f2009-12-23 14:35:29 -0800421
Ashok Bhat98071552014-02-12 09:54:43 +0000422 jlong *jIds = _env->GetLongArrayElements(_ids, NULL);
423 jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
424
425 RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement));
426 uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t));
427
428 for(int i = 0; i < fieldCount; i ++) {
429 ids[i] = (RsElement)jIds[i];
430 arraySizes[i] = (uint32_t)jArraySizes[i];
431 }
Jason Sams718cd1f2009-12-23 14:35:29 -0800432
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800433 AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
434
435 const char **nameArray = names.c_str();
436 size_t *sizeArray = names.c_str_len();
437
Tim Murray3aa89c12014-08-18 17:51:22 -0700438 jlong id = (jlong)(uintptr_t)rsElementCreate2((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +0000439 (const RsElement *)ids, fieldCount,
Jason Sams7a22e102011-05-06 14:14:30 -0700440 nameArray, fieldCount * sizeof(size_t), sizeArray,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700441 (const uint32_t *)arraySizes, fieldCount);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -0800442
Ashok Bhat98071552014-02-12 09:54:43 +0000443 free(ids);
444 free(arraySizes);
445 _env->ReleaseLongArrayElements(_ids, jIds, JNI_ABORT);
446 _env->ReleaseIntArrayElements(_arraySizes, jArraySizes, JNI_ABORT);
447
Tim Murray3aa89c12014-08-18 17:51:22 -0700448 return (jlong)(uintptr_t)id;
Jason Samsd19f10d2009-05-22 14:03:28 -0700449}
450
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700451static void
Tim Murray460a0492013-11-19 12:45:54 -0800452nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700453{
454 int dataSize = _env->GetArrayLength(_elementData);
Tim Murray71a01b82014-01-07 15:36:19 -0800455 LOG_API("nElementGetNativeData, con(%p)", (RsContext)con);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700456
457 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
458 assert(dataSize == 5);
459
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000460 uintptr_t elementData[5];
Tim Murrayeff663f2013-11-15 13:08:30 -0800461 rsaElementGetNativeData((RsContext)con, (RsElement)id, elementData, dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700462
463 for(jint i = 0; i < dataSize; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000464 const jint data = (jint)elementData[i];
465 _env->SetIntArrayRegion(_elementData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700466 }
467}
468
469
470static void
Tim Murray460a0492013-11-19 12:45:54 -0800471nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id,
Ashok Bhat98071552014-02-12 09:54:43 +0000472 jlongArray _IDs,
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700473 jobjectArray _names,
474 jintArray _arraySizes)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700475{
Ashok Bhat98071552014-02-12 09:54:43 +0000476 uint32_t dataSize = _env->GetArrayLength(_IDs);
Tim Murray71a01b82014-01-07 15:36:19 -0800477 LOG_API("nElementGetSubElements, con(%p)", (RsContext)con);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700478
Ashok Bhat98071552014-02-12 09:54:43 +0000479 uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t));
480 const char **names = (const char **)malloc(dataSize * sizeof(const char *));
Narayan Kamath78c0ce52014-03-19 10:15:51 +0000481 uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t));
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700482
Tim Murrayeff663f2013-11-15 13:08:30 -0800483 rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700484
Ashok Bhat98071552014-02-12 09:54:43 +0000485 for(uint32_t i = 0; i < dataSize; i++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700486 const jlong id = (jlong)(uintptr_t)ids[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000487 const jint arraySize = (jint)arraySizes[i];
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700488 _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
Ashok Bhat98071552014-02-12 09:54:43 +0000489 _env->SetLongArrayRegion(_IDs, i, 1, &id);
490 _env->SetIntArrayRegion(_arraySizes, i, 1, &arraySize);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700491 }
492
493 free(ids);
494 free(names);
Alex Sakhartchouk7d5f5e72011-10-18 11:08:31 -0700495 free(arraySizes);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700496}
497
Jason Samsd19f10d2009-05-22 14:03:28 -0700498// -----------------------------------
499
Tim Murray460a0492013-11-19 12:45:54 -0800500static jlong
501nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid,
Jason Samsb109cc72013-01-07 18:20:12 -0800502 jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
Jason Samsd19f10d2009-05-22 14:03:28 -0700503{
Jason Samsb109cc72013-01-07 18:20:12 -0800504 LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
Tim Murray71a01b82014-01-07 15:36:19 -0800505 (RsContext)con, eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Sams3b9c52a2010-10-14 17:48:46 -0700506
Tim Murray3aa89c12014-08-18 17:51:22 -0700507 return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv);
Jason Samsd19f10d2009-05-22 14:03:28 -0700508}
509
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700510static void
Ashok Bhat98071552014-02-12 09:54:43 +0000511nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray _typeData)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700512{
513 // We are packing 6 items: mDimX; mDimY; mDimZ;
514 // mDimLOD; mDimFaces; mElement; into typeData
515 int elementCount = _env->GetArrayLength(_typeData);
516
517 assert(elementCount == 6);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000518 LOG_API("nTypeGetNativeData, con(%p)", (RsContext)con);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700519
Ashok Bhat98071552014-02-12 09:54:43 +0000520 uintptr_t typeData[6];
Tim Murrayeff663f2013-11-15 13:08:30 -0800521 rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700522
523 for(jint i = 0; i < elementCount; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -0700524 const jlong data = (jlong)(uintptr_t)typeData[i];
Ashok Bhat98071552014-02-12 09:54:43 +0000525 _env->SetLongArrayRegion(_typeData, i, 1, &data);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700526 }
527}
528
Jason Samsd19f10d2009-05-22 14:03:28 -0700529// -----------------------------------
530
Tim Murray460a0492013-11-19 12:45:54 -0800531static jlong
Ashok Bhat98071552014-02-12 09:54:43 +0000532nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage, jlong pointer)
Jason Samsd19f10d2009-05-22 14:03:28 -0700533{
Tim Murray71a01b82014-01-07 15:36:19 -0800534 LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", (RsContext)con, (RsElement)type, mips, usage, (void *)pointer);
Tim Murray3aa89c12014-08-18 17:51:22 -0700535 return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uintptr_t)pointer);
Jason Samsd19f10d2009-05-22 14:03:28 -0700536}
537
Jason Samsd19f10d2009-05-22 14:03:28 -0700538static void
Tim Murray460a0492013-11-19 12:45:54 -0800539nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits)
Jason Sams5476b452010-12-08 16:14:36 -0800540{
Tim Murray71a01b82014-01-07 15:36:19 -0800541 LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a, bits);
Tim Murrayeff663f2013-11-15 13:08:30 -0800542 rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits);
Jason Sams5476b452010-12-08 16:14:36 -0800543}
544
Jason Sams72226e02013-02-22 12:45:54 -0800545static jobject
Tim Murray460a0492013-11-19 12:45:54 -0800546nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a)
Jason Sams615e7ce2012-01-13 14:01:20 -0800547{
Tim Murray71a01b82014-01-07 15:36:19 -0800548 LOG_API("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
Jason Sams615e7ce2012-01-13 14:01:20 -0800549
Tim Murrayeff663f2013-11-15 13:08:30 -0800550 IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con, (RsAllocation)a);
Jason Sams72226e02013-02-22 12:45:54 -0800551 sp<IGraphicBufferProducer> bp = v;
552 v->decStrong(NULL);
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700553
Jason Sams72226e02013-02-22 12:45:54 -0800554 jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp);
555 return o;
Jason Samsfe1d5ff2012-03-23 11:47:26 -0700556}
557
558static void
Tim Murray460a0492013-11-19 12:45:54 -0800559nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur)
Jason Sams163766c2012-02-15 12:04:24 -0800560{
Stephen Hines06883b72012-05-16 18:01:34 -0700561 LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)",
Tim Murray71a01b82014-01-07 15:36:19 -0800562 (RsContext)con, (RsAllocation)alloc, (Surface *)sur);
Jason Sams163766c2012-02-15 12:04:24 -0800563
Jason Samsfb9aa9f2012-03-28 15:30:07 -0700564 sp<Surface> s;
Jason Sams163766c2012-02-15 12:04:24 -0800565 if (sur != 0) {
Jeff Brown64a55af2012-08-26 02:47:39 -0700566 s = android_view_Surface_getSurface(_env, sur);
Jason Sams163766c2012-02-15 12:04:24 -0800567 }
568
Tim Murray460a0492013-11-19 12:45:54 -0800569 rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc, static_cast<ANativeWindow *>(s.get()));
Jason Sams163766c2012-02-15 12:04:24 -0800570}
571
572static void
Tim Murray460a0492013-11-19 12:45:54 -0800573nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800574{
Tim Murray71a01b82014-01-07 15:36:19 -0800575 LOG_API("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, alloc);
Tim Murray460a0492013-11-19 12:45:54 -0800576 rsAllocationIoSend((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800577}
578
579static void
Tim Murray460a0492013-11-19 12:45:54 -0800580nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Sams163766c2012-02-15 12:04:24 -0800581{
Tim Murray71a01b82014-01-07 15:36:19 -0800582 LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, alloc);
Tim Murray460a0492013-11-19 12:45:54 -0800583 rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc);
Jason Sams163766c2012-02-15 12:04:24 -0800584}
585
586
587static void
Tim Murray460a0492013-11-19 12:45:54 -0800588nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)
Jason Samsf7086092011-01-12 13:28:37 -0800589{
Tim Murray71a01b82014-01-07 15:36:19 -0800590 LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc);
Tim Murrayeff663f2013-11-15 13:08:30 -0800591 rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc);
Jason Samsf7086092011-01-12 13:28:37 -0800592}
593
Tim Murray460a0492013-11-19 12:45:54 -0800594static jlong
595nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage)
Jason Samsffe9f482009-06-01 17:45:53 -0700596{
Jason Samsffe9f482009-06-01 17:45:53 -0700597 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000598 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Samsffe9f482009-06-01 17:45:53 -0700599 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsffe9f482009-06-01 17:45:53 -0700600
Jason Sams5476b452010-12-08 16:14:36 -0800601 bitmap.lockPixels();
602 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700603 jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700604 (RsType)type, (RsAllocationMipmapControl)mip,
605 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800606 bitmap.unlockPixels();
607 return id;
Jason Samsffe9f482009-06-01 17:45:53 -0700608}
Jason Samsfe08d992009-05-27 14:45:32 -0700609
Tim Murray460a0492013-11-19 12:45:54 -0800610static jlong
611nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage)
Tim Murraya3145512012-12-04 17:59:29 -0800612{
613 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000614 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Tim Murraya3145512012-12-04 17:59:29 -0800615 const SkBitmap& bitmap(*nativeBitmap);
616
617 bitmap.lockPixels();
618 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700619 jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
Tim Murraya3145512012-12-04 17:59:29 -0800620 (RsType)type, (RsAllocationMipmapControl)mip,
Ashok Bhat98071552014-02-12 09:54:43 +0000621 (uint32_t)usage, (uintptr_t)ptr);
Tim Murraya3145512012-12-04 17:59:29 -0800622 bitmap.unlockPixels();
623 return id;
624}
625
Tim Murray460a0492013-11-19 12:45:54 -0800626static jlong
627nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage)
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800628{
629 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000630 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800631 const SkBitmap& bitmap(*nativeBitmap);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800632
Jason Sams5476b452010-12-08 16:14:36 -0800633 bitmap.lockPixels();
634 const void* ptr = bitmap.getPixels();
Tim Murray3aa89c12014-08-18 17:51:22 -0700635 jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
Jason Sams65bdaf12011-04-26 14:50:00 -0700636 (RsType)type, (RsAllocationMipmapControl)mip,
637 ptr, bitmap.getSize(), usage);
Jason Sams5476b452010-12-08 16:14:36 -0800638 bitmap.unlockPixels();
639 return id;
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800640}
641
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700642static void
Tim Murray460a0492013-11-19 12:45:54 -0800643nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700644{
645 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000646 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700647 const SkBitmap& bitmap(*nativeBitmap);
Jason Samsf7086092011-01-12 13:28:37 -0800648 int w = bitmap.width();
649 int h = bitmap.height();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700650
Jason Sams4ef66502010-12-10 16:03:15 -0800651 bitmap.lockPixels();
652 const void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800653 rsAllocation2DData((RsContext)con, (RsAllocation)alloc, 0, 0,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700654 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray38faea302012-11-27 14:55:08 -0800655 w, h, ptr, bitmap.getSize(), 0);
Jason Sams4ef66502010-12-10 16:03:15 -0800656 bitmap.unlockPixels();
657}
658
659static void
Tim Murray460a0492013-11-19 12:45:54 -0800660nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
Jason Sams4ef66502010-12-10 16:03:15 -0800661{
662 SkBitmap const * nativeBitmap =
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000663 (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
Jason Sams4ef66502010-12-10 16:03:15 -0800664 const SkBitmap& bitmap(*nativeBitmap);
665
666 bitmap.lockPixels();
667 void* ptr = bitmap.getPixels();
Tim Murrayeff663f2013-11-15 13:08:30 -0800668 rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.getSize());
Jason Sams4ef66502010-12-10 16:03:15 -0800669 bitmap.unlockPixels();
Alex Sakhartchouk835b8542011-07-20 14:33:10 -0700670 bitmap.notifyPixelsChanged();
Alex Sakhartchouk26ae3902010-10-11 12:35:15 -0700671}
672
Jason Sams8a647432010-03-01 15:31:04 -0800673static void ReleaseBitmapCallback(void *bmp)
674{
675 SkBitmap const * nativeBitmap = (SkBitmap const *)bmp;
676 nativeBitmap->unlockPixels();
677}
678
Romain Guy650a3eb2009-08-31 14:06:43 -0700679
Stephen Hines414fa2c2014-04-17 01:02:42 -0700680// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700681static void
Tim Murray460a0492013-11-19 12:45:54 -0800682nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000683 jint count, jobject data, jint sizeBytes, jint dataType)
Jason Samsd19f10d2009-05-22 14:03:28 -0700684{
Jason Samse729a942013-11-06 11:22:02 -0800685 RsAllocation *alloc = (RsAllocation *)_alloc;
Tim Murray71a01b82014-01-07 15:36:19 -0800686 LOG_API("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)",
687 (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes, dataType);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700688 PER_ARRAY_TYPE(NULL, rsAllocation1DData, true, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsd19f10d2009-05-22 14:03:28 -0700689}
690
Stephen Hines414fa2c2014-04-17 01:02:42 -0700691// Copies from the Java array data into the Allocation pointed to by alloc.
Jason Samsd19f10d2009-05-22 14:03:28 -0700692static void
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000693// native void rsnAllocationElementData1D(long con, long id, int xoff, int compIdx, byte[] d, int sizeBytes);
694nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
Jason Sams49bdaf02010-08-31 13:50:42 -0700695{
696 jint len = _env->GetArrayLength(data);
Tim Murray71a01b82014-01-07 15:36:19 -0800697 LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes);
Jason Sams49bdaf02010-08-31 13:50:42 -0700698 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Tim Murrayeff663f2013-11-15 13:08:30 -0800699 rsAllocation1DElementData((RsContext)con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
Jason Sams49bdaf02010-08-31 13:50:42 -0700700 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
701}
702
Stephen Hines414fa2c2014-04-17 01:02:42 -0700703// Copies from the Java object data into the Allocation pointed to by _alloc.
Jason Sams49bdaf02010-08-31 13:50:42 -0700704static void
Tim Murray460a0492013-11-19 12:45:54 -0800705nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000706 jint w, jint h, jobject data, jint sizeBytes, jint dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800707{
Jason Samse729a942013-11-06 11:22:02 -0800708 RsAllocation *alloc = (RsAllocation *)_alloc;
709 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
710 LOG_API("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)",
Tim Murray71a01b82014-01-07 15:36:19 -0800711 (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700712 PER_ARRAY_TYPE(NULL, rsAllocation2DData, true, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Samsd19f10d2009-05-22 14:03:28 -0700713}
714
Stephen Hines414fa2c2014-04-17 01:02:42 -0700715// Copies from the Allocation pointed to by srcAlloc into the Allocation
716// pointed to by dstAlloc.
Jason Sams40a29e82009-08-10 14:55:26 -0700717static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800718nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -0800719 jlong dstAlloc, jint dstXoff, jint dstYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700720 jint dstMip, jint dstFace,
721 jint width, jint height,
Tim Murray460a0492013-11-19 12:45:54 -0800722 jlong srcAlloc, jint srcXoff, jint srcYoff,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700723 jint srcMip, jint srcFace)
724{
Jason Sams4c2e4c82012-02-07 15:32:08 -0800725 LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700726 " dstMip(%i), dstFace(%i), width(%i), height(%i),"
727 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
Tim Murray71a01b82014-01-07 15:36:19 -0800728 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700729 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
730
Tim Murrayeff663f2013-11-15 13:08:30 -0800731 rsAllocationCopy2DRange((RsContext)con,
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700732 (RsAllocation)dstAlloc,
733 dstXoff, dstYoff,
734 dstMip, dstFace,
735 width, height,
736 (RsAllocation)srcAlloc,
737 srcXoff, srcYoff,
738 srcMip, srcFace);
739}
740
Stephen Hines414fa2c2014-04-17 01:02:42 -0700741// Copies from the Java object data into the Allocation pointed to by _alloc.
Alex Sakhartchouk304b1f52011-06-14 11:13:19 -0700742static void
Tim Murray460a0492013-11-19 12:45:54 -0800743nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
Jason Samse729a942013-11-06 11:22:02 -0800744 jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
Jason Samsb05d6892013-04-09 15:59:24 -0700745{
Jason Samse729a942013-11-06 11:22:02 -0800746 RsAllocation *alloc = (RsAllocation *)_alloc;
747 LOG_API("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i), h(%i), d(%i), sizeBytes(%i)",
Tim Murray71a01b82014-01-07 15:36:19 -0800748 (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, sizeBytes);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700749 PER_ARRAY_TYPE(NULL, rsAllocation3DData, true, (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
Jason Samsb05d6892013-04-09 15:59:24 -0700750}
751
Stephen Hines414fa2c2014-04-17 01:02:42 -0700752// Copies from the Allocation pointed to by srcAlloc into the Allocation
753// pointed to by dstAlloc.
Jason Samsb05d6892013-04-09 15:59:24 -0700754static void
Tim Murrayeff663f2013-11-15 13:08:30 -0800755nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -0800756 jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700757 jint dstMip,
758 jint width, jint height, jint depth,
Tim Murray460a0492013-11-19 12:45:54 -0800759 jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
Jason Samsb05d6892013-04-09 15:59:24 -0700760 jint srcMip)
761{
762 LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
763 " dstMip(%i), width(%i), height(%i),"
764 " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
Tim Murray71a01b82014-01-07 15:36:19 -0800765 (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip,
766 width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip);
Jason Samsb05d6892013-04-09 15:59:24 -0700767
Tim Murrayeff663f2013-11-15 13:08:30 -0800768 rsAllocationCopy3DRange((RsContext)con,
Jason Samsb05d6892013-04-09 15:59:24 -0700769 (RsAllocation)dstAlloc,
770 dstXoff, dstYoff, dstZoff, dstMip,
771 width, height, depth,
772 (RsAllocation)srcAlloc,
773 srcXoff, srcYoff, srcZoff, srcMip);
774}
775
Jason Sams21659ac2013-11-06 15:08:07 -0800776
Stephen Hines414fa2c2014-04-17 01:02:42 -0700777// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsb05d6892013-04-09 15:59:24 -0700778static void
Tim Murray460a0492013-11-19 12:45:54 -0800779nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType)
Jason Sams40a29e82009-08-10 14:55:26 -0700780{
Jason Sams21659ac2013-11-06 15:08:07 -0800781 RsAllocation *alloc = (RsAllocation *)_alloc;
Tim Murray71a01b82014-01-07 15:36:19 -0800782 LOG_API("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700783 PER_ARRAY_TYPE(0, rsAllocationRead, false, (RsContext)con, alloc, ptr, len * typeBytes);
Jason Sams40a29e82009-08-10 14:55:26 -0700784}
785
Stephen Hines414fa2c2014-04-17 01:02:42 -0700786// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Sams40a29e82009-08-10 14:55:26 -0700787static void
Tim Murray460a0492013-11-19 12:45:54 -0800788nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
Jason Sams21659ac2013-11-06 15:08:07 -0800789 jint count, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800790{
Jason Sams21659ac2013-11-06 15:08:07 -0800791 RsAllocation *alloc = (RsAllocation *)_alloc;
Tim Murray71a01b82014-01-07 15:36:19 -0800792 LOG_API("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)",
793 (RsContext)con, alloc, offset, count, sizeBytes, dataType);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700794 PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
Jason Samsfb9f82c2011-01-12 14:53:25 -0800795}
796
Stephen Hines414fa2c2014-04-17 01:02:42 -0700797// Copies from the Allocation pointed to by _alloc into the Java object data.
Jason Samsfb9f82c2011-01-12 14:53:25 -0800798static void
Tim Murray460a0492013-11-19 12:45:54 -0800799nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
Jason Sams21659ac2013-11-06 15:08:07 -0800800 jint w, jint h, jobject data, int sizeBytes, int dataType)
Jason Samsfb9f82c2011-01-12 14:53:25 -0800801{
Jason Sams21659ac2013-11-06 15:08:07 -0800802 RsAllocation *alloc = (RsAllocation *)_alloc;
803 RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
804 LOG_API("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)",
Tim Murray71a01b82014-01-07 15:36:19 -0800805 (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
Stephen Hines414fa2c2014-04-17 01:02:42 -0700806 PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
Jason Sams40a29e82009-08-10 14:55:26 -0700807}
Jason Samsd19f10d2009-05-22 14:03:28 -0700808
Tim Murray460a0492013-11-19 12:45:54 -0800809static jlong
810nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a)
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700811{
Tim Murray71a01b82014-01-07 15:36:19 -0800812 LOG_API("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a);
Tim Murray3aa89c12014-08-18 17:51:22 -0700813 return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a);
Alex Sakhartchoukdfac8142010-07-15 11:33:03 -0700814}
815
Jason Sams5edc6082010-10-05 13:32:49 -0700816static void
Tim Murray460a0492013-11-19 12:45:54 -0800817nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX)
Jason Sams5edc6082010-10-05 13:32:49 -0700818{
Tim Murray71a01b82014-01-07 15:36:19 -0800819 LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con, (RsAllocation)alloc, dimX);
Tim Murrayeff663f2013-11-15 13:08:30 -0800820 rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX);
Jason Sams5edc6082010-10-05 13:32:49 -0700821}
822
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700823// -----------------------------------
824
Tim Murray460a0492013-11-19 12:45:54 -0800825static jlong
826nFileA3DCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con, jlong native_asset)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700827{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700828 Asset* asset = reinterpret_cast<Asset*>(native_asset);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000829 ALOGV("______nFileA3D %p", asset);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700830
Tim Murray3aa89c12014-08-18 17:51:22 -0700831 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromMemory((RsContext)con, asset->getBuffer(false), asset->getLength());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800832 return id;
833}
834
Tim Murray460a0492013-11-19 12:45:54 -0800835static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800836nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800837{
838 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
839 if (mgr == NULL) {
840 return 0;
841 }
842
843 AutoJavaStringToUTF8 str(_env, _path);
844 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
845 if (asset == NULL) {
846 return 0;
847 }
848
Tim Murray3aa89c12014-08-18 17:51:22 -0700849 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromAsset((RsContext)con, asset);
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800850 return id;
851}
852
Tim Murray460a0492013-11-19 12:45:54 -0800853static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800854nFileA3DCreateFromFile(JNIEnv *_env, jobject _this, jlong con, jstring fileName)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800855{
856 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -0700857 jlong id = (jlong)(uintptr_t)rsaFileA3DCreateFromFile((RsContext)con, fileNameUTF.c_str());
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800858
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700859 return id;
860}
861
Tim Murray460a0492013-11-19 12:45:54 -0800862static jint
863nFileA3DGetNumIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700864{
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700865 int32_t numEntries = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -0800866 rsaFileA3DGetNumIndexEntries((RsContext)con, &numEntries, (RsFile)fileA3D);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000867 return (jint)numEntries;
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700868}
869
870static void
Tim Murray460a0492013-11-19 12:45:54 -0800871nFileA3DGetIndexEntries(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint numEntries, jintArray _ids, jobjectArray _entries)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700872{
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000873 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700874 RsFileIndexEntry *fileEntries = (RsFileIndexEntry*)malloc((uint32_t)numEntries * sizeof(RsFileIndexEntry));
875
Tim Murrayeff663f2013-11-15 13:08:30 -0800876 rsaFileA3DGetIndexEntries((RsContext)con, fileEntries, (uint32_t)numEntries, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700877
878 for(jint i = 0; i < numEntries; i ++) {
879 _env->SetObjectArrayElement(_entries, i, _env->NewStringUTF(fileEntries[i].objectName));
880 _env->SetIntArrayRegion(_ids, i, 1, (const jint*)&fileEntries[i].classID);
881 }
882
883 free(fileEntries);
884}
885
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000886static jlong
Tim Murray460a0492013-11-19 12:45:54 -0800887nFileA3DGetEntryByIndex(JNIEnv *_env, jobject _this, jlong con, jlong fileA3D, jint index)
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700888{
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000889 ALOGV("______nFileA3D %p", (RsFile) fileA3D);
Tim Murray3aa89c12014-08-18 17:51:22 -0700890 jlong id = (jlong)(uintptr_t)rsaFileA3DGetEntryByIndex((RsContext)con, (uint32_t)index, (RsFile)fileA3D);
Alex Sakhartchoukaae74ad2010-06-04 10:06:50 -0700891 return id;
892}
Jason Samsd19f10d2009-05-22 14:03:28 -0700893
894// -----------------------------------
895
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000896static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800897nFontCreateFromFile(JNIEnv *_env, jobject _this, jlong con,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800898 jstring fileName, jfloat fontSize, jint dpi)
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700899{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800900 AutoJavaStringToUTF8 fileNameUTF(_env, fileName);
Tim Murray3aa89c12014-08-18 17:51:22 -0700901 jlong id = (jlong)(uintptr_t)rsFontCreateFromFile((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700902 fileNameUTF.c_str(), fileNameUTF.length(),
903 fontSize, dpi);
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700904
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800905 return id;
906}
907
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000908static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800909nFontCreateFromAssetStream(JNIEnv *_env, jobject _this, jlong con,
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000910 jstring name, jfloat fontSize, jint dpi, jlong native_asset)
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800911{
912 Asset* asset = reinterpret_cast<Asset*>(native_asset);
913 AutoJavaStringToUTF8 nameUTF(_env, name);
914
Tim Murray3aa89c12014-08-18 17:51:22 -0700915 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700916 nameUTF.c_str(), nameUTF.length(),
917 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800918 asset->getBuffer(false), asset->getLength());
919 return id;
920}
921
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000922static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -0800923nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800924 jfloat fontSize, jint dpi)
925{
926 AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr);
927 if (mgr == NULL) {
928 return 0;
929 }
930
931 AutoJavaStringToUTF8 str(_env, _path);
932 Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER);
933 if (asset == NULL) {
934 return 0;
935 }
936
Tim Murray3aa89c12014-08-18 17:51:22 -0700937 jlong id = (jlong)(uintptr_t)rsFontCreateFromMemory((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -0700938 str.c_str(), str.length(),
939 fontSize, dpi,
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -0800940 asset->getBuffer(false), asset->getLength());
941 delete asset;
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -0700942 return id;
943}
944
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700945// -----------------------------------
946
947static void
Tim Murray460a0492013-11-19 12:45:54 -0800948nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot)
Jason Samsd19f10d2009-05-22 14:03:28 -0700949{
Tim Murray71a01b82014-01-07 15:36:19 -0800950 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Tim Murrayeff663f2013-11-15 13:08:30 -0800951 rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot);
Jason Samsd19f10d2009-05-22 14:03:28 -0700952}
953
954static void
Tim Murray460a0492013-11-19 12:45:54 -0800955nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val)
Jason Sams4d339932010-05-11 14:03:58 -0700956{
Tim Murray71a01b82014-01-07 15:36:19 -0800957 LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, slot, val);
Tim Murrayeff663f2013-11-15 13:08:30 -0800958 rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700959}
960
Tim Murray7c4caad2013-04-10 16:21:40 -0700961static jint
Tim Murray460a0492013-11-19 12:45:54 -0800962nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -0700963{
Tim Murray71a01b82014-01-07 15:36:19 -0800964 LOG_API("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -0700965 int value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -0800966 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -0700967 return value;
968}
969
Jason Sams4d339932010-05-11 14:03:58 -0700970static void
Tim Murray460a0492013-11-19 12:45:54 -0800971nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800972{
Tim Murray71a01b82014-01-07 15:36:19 -0800973 LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, slot, val);
Tim Murrayeff663f2013-11-15 13:08:30 -0800974 rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800975}
976
977static void
Tim Murray460a0492013-11-19 12:45:54 -0800978nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val)
Stephen Hines031ec58c2010-10-11 10:54:21 -0700979{
Tim Murray71a01b82014-01-07 15:36:19 -0800980 LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", (RsContext)con, (void *)script, slot, val);
Tim Murrayeff663f2013-11-15 13:08:30 -0800981 rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val);
Stephen Hines031ec58c2010-10-11 10:54:21 -0700982}
983
Tim Murray7c4caad2013-04-10 16:21:40 -0700984static jlong
Tim Murray460a0492013-11-19 12:45:54 -0800985nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -0700986{
Tim Murray71a01b82014-01-07 15:36:19 -0800987 LOG_API("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -0700988 jlong value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -0800989 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -0700990 return value;
991}
992
Stephen Hines031ec58c2010-10-11 10:54:21 -0700993static void
Tim Murray460a0492013-11-19 12:45:54 -0800994nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val)
Jason Sams4d339932010-05-11 14:03:58 -0700995{
Tim Murray71a01b82014-01-07 15:36:19 -0800996 LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script, slot, val);
Tim Murrayeff663f2013-11-15 13:08:30 -0800997 rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val);
Jason Sams4d339932010-05-11 14:03:58 -0700998}
999
Tim Murray7c4caad2013-04-10 16:21:40 -07001000static jfloat
Tim Murray460a0492013-11-19 12:45:54 -08001001nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001002{
Tim Murray71a01b82014-01-07 15:36:19 -08001003 LOG_API("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -07001004 jfloat value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001005 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001006 return value;
1007}
1008
Jason Sams4d339932010-05-11 14:03:58 -07001009static void
Tim Murray460a0492013-11-19 12:45:54 -08001010nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val)
Stephen Hinesca54ec32010-09-20 17:20:30 -07001011{
Tim Murray71a01b82014-01-07 15:36:19 -08001012 LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script, slot, val);
Tim Murrayeff663f2013-11-15 13:08:30 -08001013 rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val);
Stephen Hinesca54ec32010-09-20 17:20:30 -07001014}
1015
Tim Murray7c4caad2013-04-10 16:21:40 -07001016static jdouble
Tim Murray460a0492013-11-19 12:45:54 -08001017nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot)
Tim Murray7c4caad2013-04-10 16:21:40 -07001018{
Tim Murray71a01b82014-01-07 15:36:19 -08001019 LOG_API("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -07001020 jdouble value = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001021 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value));
Tim Murray7c4caad2013-04-10 16:21:40 -07001022 return value;
1023}
1024
Stephen Hinesca54ec32010-09-20 17:20:30 -07001025static void
Tim Murray460a0492013-11-19 12:45:54 -08001026nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001027{
Tim Murray71a01b82014-01-07 15:36:19 -08001028 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Jason Sams4d339932010-05-11 14:03:58 -07001029 jint len = _env->GetArrayLength(data);
1030 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Tim Murrayeff663f2013-11-15 13:08:30 -08001031 rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001032 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1033}
1034
Stephen Hinesadeb8092012-04-20 14:26:06 -07001035static void
Tim Murray460a0492013-11-19 12:45:54 -08001036nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Tim Murray7c4caad2013-04-10 16:21:40 -07001037{
Tim Murray71a01b82014-01-07 15:36:19 -08001038 LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murray7c4caad2013-04-10 16:21:40 -07001039 jint len = _env->GetArrayLength(data);
1040 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Tim Murrayeff663f2013-11-15 13:08:30 -08001041 rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
Stephen Hines414fa2c2014-04-17 01:02:42 -07001042 _env->ReleaseByteArrayElements(data, ptr, 0);
Tim Murray7c4caad2013-04-10 16:21:40 -07001043}
1044
1045static void
Tim Murray460a0492013-11-19 12:45:54 -08001046nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data, jlong elem, jintArray dims)
Stephen Hinesadeb8092012-04-20 14:26:06 -07001047{
Tim Murray71a01b82014-01-07 15:36:19 -08001048 LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001049 jint len = _env->GetArrayLength(data);
1050 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
1051 jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
1052 jint *dimsPtr = _env->GetIntArrayElements(dims, NULL);
Tim Murrayeff663f2013-11-15 13:08:30 -08001053 rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem,
Stephen Hinesbc5d3ee2014-06-25 00:03:39 -07001054 (const uint32_t*) dimsPtr, dimsLen);
Stephen Hinesadeb8092012-04-20 14:26:06 -07001055 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1056 _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
1057}
1058
Jason Samsd19f10d2009-05-22 14:03:28 -07001059
1060static void
Tim Murray460a0492013-11-19 12:45:54 -08001061nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone)
Jason Samsd19f10d2009-05-22 14:03:28 -07001062{
Tim Murray71a01b82014-01-07 15:36:19 -08001063 LOG_API("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script);
Romain Guy584a3752009-07-30 18:45:01 -07001064
1065 jint length = _env->GetArrayLength(timeZone);
1066 jbyte* timeZone_ptr;
1067 timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
1068
Tim Murrayeff663f2013-11-15 13:08:30 -08001069 rsScriptSetTimeZone((RsContext)con, (RsScript)script, (const char *)timeZone_ptr, length);
Romain Guy584a3752009-07-30 18:45:01 -07001070
1071 if (timeZone_ptr) {
1072 _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
1073 }
1074}
1075
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001076static void
Tim Murray460a0492013-11-19 12:45:54 -08001077nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot)
Jason Samsbe2e8412009-09-16 15:04:38 -07001078{
Tim Murray71a01b82014-01-07 15:36:19 -08001079 LOG_API("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj);
Tim Murrayeff663f2013-11-15 13:08:30 -08001080 rsScriptInvoke((RsContext)con, (RsScript)obj, slot);
Jason Samsbe2e8412009-09-16 15:04:38 -07001081}
1082
1083static void
Tim Murray460a0492013-11-19 12:45:54 -08001084nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data)
Jason Sams4d339932010-05-11 14:03:58 -07001085{
Tim Murray71a01b82014-01-07 15:36:19 -08001086 LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Jason Sams4d339932010-05-11 14:03:58 -07001087 jint len = _env->GetArrayLength(data);
1088 jbyte *ptr = _env->GetByteArrayElements(data, NULL);
Tim Murrayeff663f2013-11-15 13:08:30 -08001089 rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len);
Jason Sams4d339932010-05-11 14:03:58 -07001090 _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
1091}
1092
Jason Sams6e494d32011-04-27 16:33:11 -07001093static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001094nScriptForEach(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001095 jlong script, jint slot, jlong ain, jlong aout)
Jason Sams6e494d32011-04-27 16:33:11 -07001096{
Tim Murray71a01b82014-01-07 15:36:19 -08001097 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murrayeff663f2013-11-15 13:08:30 -08001098 rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, NULL, 0);
Jason Sams6e494d32011-04-27 16:33:11 -07001099}
1100static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001101nScriptForEachV(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001102 jlong script, jint slot, jlong ain, jlong aout, jbyteArray params)
Jason Sams6e494d32011-04-27 16:33:11 -07001103{
Tim Murray71a01b82014-01-07 15:36:19 -08001104 LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Jason Sams6e494d32011-04-27 16:33:11 -07001105 jint len = _env->GetArrayLength(params);
1106 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
Tim Murrayeff663f2013-11-15 13:08:30 -08001107 rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, NULL, 0);
Jason Sams6e494d32011-04-27 16:33:11 -07001108 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1109}
1110
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001111static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001112nScriptForEachClipped(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001113 jlong script, jint slot, jlong ain, jlong aout,
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001114 jint xstart, jint xend,
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001115 jint ystart, jint yend, jint zstart, jint zend)
1116{
Tim Murray71a01b82014-01-07 15:36:19 -08001117 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001118 RsScriptCall sc;
1119 sc.xStart = xstart;
1120 sc.xEnd = xend;
1121 sc.yStart = ystart;
1122 sc.yEnd = yend;
1123 sc.zStart = zstart;
1124 sc.zEnd = zend;
1125 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1126 sc.arrayStart = 0;
1127 sc.arrayEnd = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001128 rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc));
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001129}
1130
1131static void
Tim Murrayeff663f2013-11-15 13:08:30 -08001132nScriptForEachClippedV(JNIEnv *_env, jobject _this, jlong con,
Tim Murray460a0492013-11-19 12:45:54 -08001133 jlong script, jint slot, jlong ain, jlong aout,
Stephen Hinesdac6ed02013-02-13 00:09:02 -08001134 jbyteArray params, jint xstart, jint xend,
1135 jint ystart, jint yend, jint zstart, jint zend)
1136{
Tim Murray71a01b82014-01-07 15:36:19 -08001137 LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001138 jint len = _env->GetArrayLength(params);
1139 jbyte *ptr = _env->GetByteArrayElements(params, NULL);
1140 RsScriptCall sc;
1141 sc.xStart = xstart;
1142 sc.xEnd = xend;
1143 sc.yStart = ystart;
1144 sc.yEnd = yend;
1145 sc.zStart = zstart;
1146 sc.zEnd = zend;
1147 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1148 sc.arrayStart = 0;
1149 sc.arrayEnd = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001150 rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, &sc, sizeof(sc));
Tim Murrayeb8c29c2013-02-07 12:16:41 -08001151 _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
1152}
Jason Samsfbf0b9e2009-08-13 12:59:04 -07001153
Chris Wailes94961062014-06-11 12:01:28 -07001154static void
1155nScriptForEachMultiClipped(JNIEnv *_env, jobject _this, jlong con,
1156 jlong script, jint slot, jlongArray ains, jlong aout,
1157 jint xstart, jint xend,
1158 jint ystart, jint yend, jint zstart, jint zend)
1159{
1160 LOG_API("nScriptForEachMultiClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1161
1162 jint in_len = _env->GetArrayLength(ains);
1163 jlong* in_ptr = _env->GetLongArrayElements(ains, NULL);
1164
1165 RsAllocation *in_allocs = NULL;
1166
1167 if (sizeof(RsAllocation) == sizeof(jlong)) {
1168 in_allocs = (RsAllocation*)in_ptr;
1169
1170 } else {
1171 // Convert from 64-bit jlong types to the native pointer type.
1172
1173 in_allocs = new RsAllocation[in_len];
1174
1175 for (int index = in_len; --index >= 0;) {
1176 in_allocs[index] = (RsAllocation)in_ptr[index];
1177 }
1178 }
1179
1180 RsScriptCall sc;
1181 sc.xStart = xstart;
1182 sc.xEnd = xend;
1183 sc.yStart = ystart;
1184 sc.yEnd = yend;
1185 sc.zStart = zstart;
1186 sc.zEnd = zend;
1187 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1188 sc.arrayStart = 0;
1189 sc.arrayEnd = 0;
1190
1191 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, in_allocs, in_len, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc));
1192
1193 if (sizeof(RsAllocation) != sizeof(jlong)) {
1194 delete[] in_allocs;
1195 }
1196
1197 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
1198}
1199
1200static void
1201nScriptForEachMultiClippedV(JNIEnv *_env, jobject _this, jlong con,
1202 jlong script, jint slot, jlongArray ains, jlong aout,
1203 jbyteArray params, jint xstart, jint xend,
1204 jint ystart, jint yend, jint zstart, jint zend)
1205{
1206 LOG_API("nScriptForEachMultiClippedV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot);
1207
1208 jint in_len = _env->GetArrayLength(ains);
1209 jlong* in_ptr = _env->GetLongArrayElements(ains, NULL);
1210
1211 RsAllocation *in_allocs = NULL;
1212
1213 if (sizeof(RsAllocation) == sizeof(jlong)) {
1214 in_allocs = (RsAllocation*)in_ptr;
1215
1216 } else {
1217 // Convert from 64-bit jlong types to the native pointer type.
1218
1219 in_allocs = new RsAllocation[in_len];
1220
1221 for (int index = in_len; --index >= 0;) {
1222 in_allocs[index] = (RsAllocation)in_ptr[index];
1223 }
1224 }
1225
1226 jint param_len = _env->GetArrayLength(params);
1227 jbyte* param_ptr = _env->GetByteArrayElements(params, NULL);
1228
1229 RsScriptCall sc;
1230 sc.xStart = xstart;
1231 sc.xEnd = xend;
1232 sc.yStart = ystart;
1233 sc.yEnd = yend;
1234 sc.zStart = zstart;
1235 sc.zEnd = zend;
1236 sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
1237 sc.arrayStart = 0;
1238 sc.arrayEnd = 0;
1239 rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, in_allocs, in_len, (RsAllocation)aout, param_ptr, param_len, &sc, sizeof(sc));
1240
1241 if (sizeof(RsAllocation) != sizeof(jlong)) {
1242 delete[] in_allocs;
1243 }
1244
1245 _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT);
1246 _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT);
1247}
1248
Jason Sams22534172009-08-04 16:58:20 -07001249// -----------------------------------
1250
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001251static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001252nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001253 jstring resName, jstring cacheDir,
1254 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001255{
Tim Murray71a01b82014-01-07 15:36:19 -08001256 LOG_API("nScriptCCreate, con(%p)", (RsContext)con);
Jason Sams22534172009-08-04 16:58:20 -07001257
Jason Samse4a06c52011-03-16 16:29:28 -07001258 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1259 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001260 jlong ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -07001261 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -07001262 jint _exception = 0;
1263 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001264 if (!scriptRef) {
1265 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001266 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001267 goto exit;
1268 }
Jack Palevich43702d82009-05-28 13:38:16 -07001269 if (length < 0) {
1270 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001271 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001272 goto exit;
1273 }
Jason Samse4a06c52011-03-16 16:29:28 -07001274 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001275 if (remaining < length) {
1276 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001277 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1278 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001279 goto exit;
1280 }
Jason Samse4a06c52011-03-16 16:29:28 -07001281 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001282 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001283
Tim Murrayeff663f2013-11-15 13:08:30 -08001284 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001285
Tim Murray3aa89c12014-08-18 17:51:22 -07001286 ret = (jlong)(uintptr_t)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001287 resNameUTF.c_str(), resNameUTF.length(),
1288 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001289 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001290
Jack Palevich43702d82009-05-28 13:38:16 -07001291exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001292 if (script_ptr) {
1293 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001294 _exception ? JNI_ABORT: 0);
1295 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001296
Tim Murray3aa89c12014-08-18 17:51:22 -07001297 return (jlong)(uintptr_t)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001298}
1299
Tim Murray460a0492013-11-19 12:45:54 -08001300static jlong
1301nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001302{
Tim Murray71a01b82014-01-07 15:36:19 -08001303 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id, (void *)eid);
Tim Murray3aa89c12014-08-18 17:51:22 -07001304 return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001305}
1306
Tim Murray460a0492013-11-19 12:45:54 -08001307static jlong
1308nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001309{
Tim Murray71a01b82014-01-07 15:36:19 -08001310 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con, (void *)sid, slot, sig);
Tim Murray3aa89c12014-08-18 17:51:22 -07001311 return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001312}
1313
Tim Murray460a0492013-11-19 12:45:54 -08001314static jlong
1315nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001316{
Tim Murray71a01b82014-01-07 15:36:19 -08001317 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid, slot);
Tim Murray3aa89c12014-08-18 17:51:22 -07001318 return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001319}
1320
Tim Murray460a0492013-11-19 12:45:54 -08001321static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001322nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1323 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001324{
Tim Murray71a01b82014-01-07 15:36:19 -08001325 LOG_API("nScriptGroupCreate, con(%p)", (RsContext)con);
Jason Sams08a81582012-09-18 12:32:10 -07001326
Ashok Bhat98071552014-02-12 09:54:43 +00001327 jint kernelsLen = _env->GetArrayLength(_kernels);
1328 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, NULL);
1329 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1330 for(int i = 0; i < kernelsLen; ++i) {
1331 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1332 }
Jason Sams08a81582012-09-18 12:32:10 -07001333
Ashok Bhat98071552014-02-12 09:54:43 +00001334 jint srcLen = _env->GetArrayLength(_src);
1335 jlong *jSrcPtr = _env->GetLongArrayElements(_src, NULL);
1336 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1337 for(int i = 0; i < srcLen; ++i) {
1338 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1339 }
Jason Sams08a81582012-09-18 12:32:10 -07001340
Ashok Bhat98071552014-02-12 09:54:43 +00001341 jint dstkLen = _env->GetArrayLength(_dstk);
1342 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, NULL);
1343 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1344 for(int i = 0; i < dstkLen; ++i) {
1345 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1346 }
1347
1348 jint dstfLen = _env->GetArrayLength(_dstf);
1349 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, NULL);
1350 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1351 for(int i = 0; i < dstfLen; ++i) {
1352 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1353 }
1354
1355 jint typesLen = _env->GetArrayLength(_types);
1356 jlong *jTypesPtr = _env->GetLongArrayElements(_types, NULL);
1357 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1358 for(int i = 0; i < typesLen; ++i) {
1359 typesPtr[i] = (RsType)jTypesPtr[i];
1360 }
1361
Tim Murray3aa89c12014-08-18 17:51:22 -07001362 jlong id = (jlong)(uintptr_t)rsScriptGroupCreate((RsContext)con,
Ashok Bhat98071552014-02-12 09:54:43 +00001363 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1364 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1365 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1366 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1367 (RsType *)typesPtr, typesLen * sizeof(RsType));
1368
1369 free(kernelsPtr);
1370 free(srcPtr);
1371 free(dstkPtr);
1372 free(dstfPtr);
1373 free(typesPtr);
1374 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1375 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1376 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1377 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1378 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001379 return id;
1380}
1381
1382static void
Tim Murray460a0492013-11-19 12:45:54 -08001383nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001384{
Tim Murray71a01b82014-01-07 15:36:19 -08001385 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
Jason Sams08a81582012-09-18 12:32:10 -07001386 (void *)gid, (void *)kid, (void *)alloc);
Tim Murrayeff663f2013-11-15 13:08:30 -08001387 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001388}
1389
1390static void
Tim Murray460a0492013-11-19 12:45:54 -08001391nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001392{
Tim Murray71a01b82014-01-07 15:36:19 -08001393 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
Jason Sams08a81582012-09-18 12:32:10 -07001394 (void *)gid, (void *)kid, (void *)alloc);
Tim Murrayeff663f2013-11-15 13:08:30 -08001395 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001396}
1397
1398static void
Tim Murray460a0492013-11-19 12:45:54 -08001399nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001400{
Tim Murray71a01b82014-01-07 15:36:19 -08001401 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
Tim Murrayeff663f2013-11-15 13:08:30 -08001402 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001403}
1404
Jason Samsd19f10d2009-05-22 14:03:28 -07001405// ---------------------------------------------------------------------------
1406
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001407static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001408nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07001409 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1410 jboolean depthMask, jboolean ditherEnable,
1411 jint srcFunc, jint destFunc,
1412 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001413{
Tim Murray71a01b82014-01-07 15:36:19 -08001414 LOG_API("nProgramStoreCreate, con(%p)", (RsContext)con);
Tim Murray3aa89c12014-08-18 17:51:22 -07001415 return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07001416 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1417 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001418}
1419
Jason Sams0011bcf2009-12-15 12:58:36 -08001420// ---------------------------------------------------------------------------
1421
1422static void
Tim Murray460a0492013-11-19 12:45:54 -08001423nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001424{
Tim Murray71a01b82014-01-07 15:36:19 -08001425 LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con, (RsProgramVertex)vpv, slot, (RsAllocation)a);
Tim Murrayeff663f2013-11-15 13:08:30 -08001426 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08001427}
Jason Sams54c0ec12009-11-30 14:49:55 -08001428
Jason Sams68afd012009-12-17 16:55:08 -08001429static void
Tim Murray460a0492013-11-19 12:45:54 -08001430nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001431{
Tim Murray71a01b82014-01-07 15:36:19 -08001432 LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Tim Murrayeff663f2013-11-15 13:08:30 -08001433 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08001434}
1435
1436static void
Tim Murray460a0492013-11-19 12:45:54 -08001437nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001438{
Tim Murray71a01b82014-01-07 15:36:19 -08001439 LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Tim Murrayeff663f2013-11-15 13:08:30 -08001440 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08001441}
1442
Jason Samsd19f10d2009-05-22 14:03:28 -07001443// ---------------------------------------------------------------------------
1444
Tim Murray460a0492013-11-19 12:45:54 -08001445static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001446nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001447 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001448{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001449 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Ashok Bhat98071552014-02-12 09:54:43 +00001450 jlong *jParamPtr = _env->GetLongArrayElements(params, NULL);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001451 jint paramLen = _env->GetArrayLength(params);
1452
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001453 int texCount = _env->GetArrayLength(texNames);
1454 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1455 const char ** nameArray = names.c_str();
1456 size_t* sizeArray = names.c_str_len();
1457
Tim Murray71a01b82014-01-07 15:36:19 -08001458 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001459
Ashok Bhat98071552014-02-12 09:54:43 +00001460 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1461 for(int i = 0; i < paramLen; ++i) {
1462 paramPtr[i] = (uintptr_t)jParamPtr[i];
1463 }
Tim Murray3aa89c12014-08-18 17:51:22 -07001464 jlong ret = (jlong)(uintptr_t)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001465 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001466 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001467
Ashok Bhat98071552014-02-12 09:54:43 +00001468 free(paramPtr);
1469 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001470 return ret;
1471}
1472
1473
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001474// ---------------------------------------------------------------------------
1475
Tim Murray460a0492013-11-19 12:45:54 -08001476static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001477nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001478 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001479{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001480 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Ashok Bhat98071552014-02-12 09:54:43 +00001481 jlong *jParamPtr = _env->GetLongArrayElements(params, NULL);
Jason Sams0011bcf2009-12-15 12:58:36 -08001482 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001483
Tim Murray71a01b82014-01-07 15:36:19 -08001484 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001485
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001486 int texCount = _env->GetArrayLength(texNames);
1487 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1488 const char ** nameArray = names.c_str();
1489 size_t* sizeArray = names.c_str_len();
1490
Ashok Bhat98071552014-02-12 09:54:43 +00001491 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1492 for(int i = 0; i < paramLen; ++i) {
1493 paramPtr[i] = (uintptr_t)jParamPtr[i];
1494 }
1495
Tim Murray3aa89c12014-08-18 17:51:22 -07001496 jlong ret = (jlong)(uintptr_t)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001497 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001498 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001499
Ashok Bhat98071552014-02-12 09:54:43 +00001500 free(paramPtr);
1501 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08001502 return ret;
1503}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001504
Jason Samsebfb4362009-09-23 13:57:02 -07001505// ---------------------------------------------------------------------------
1506
Tim Murray460a0492013-11-19 12:45:54 -08001507static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001508nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001509{
Tim Murray71a01b82014-01-07 15:36:19 -08001510 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con, pointSprite, cull);
Tim Murray3aa89c12014-08-18 17:51:22 -07001511 return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001512}
1513
Jason Samsd19f10d2009-05-22 14:03:28 -07001514
1515// ---------------------------------------------------------------------------
1516
1517static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001518nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001519{
Tim Murray71a01b82014-01-07 15:36:19 -08001520 LOG_API("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
Tim Murrayeff663f2013-11-15 13:08:30 -08001521 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001522}
1523
1524static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001525nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001526{
Tim Murray71a01b82014-01-07 15:36:19 -08001527 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
Tim Murrayeff663f2013-11-15 13:08:30 -08001528 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001529}
1530
1531static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001532nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001533{
Tim Murray71a01b82014-01-07 15:36:19 -08001534 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con, (RsProgramFragment)pf);
Tim Murrayeff663f2013-11-15 13:08:30 -08001535 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001536}
1537
Jason Sams0826a6f2009-06-15 19:04:56 -07001538static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001539nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001540{
Tim Murray71a01b82014-01-07 15:36:19 -08001541 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
Tim Murrayeff663f2013-11-15 13:08:30 -08001542 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001543}
1544
Joe Onoratod7b37742009-08-09 22:57:44 -07001545static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001546nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001547{
Tim Murray71a01b82014-01-07 15:36:19 -08001548 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
Tim Murrayeff663f2013-11-15 13:08:30 -08001549 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07001550}
1551
Joe Onoratod7b37742009-08-09 22:57:44 -07001552
Jason Sams02fb2cb2009-05-28 15:37:57 -07001553// ---------------------------------------------------------------------------
1554
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001555static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001556nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001557 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001558{
Tim Murray71a01b82014-01-07 15:36:19 -08001559 LOG_API("nSamplerCreate, con(%p)", (RsContext)con);
Tim Murray3aa89c12014-08-18 17:51:22 -07001560 return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001561 (RsSamplerValue)magFilter,
1562 (RsSamplerValue)minFilter,
1563 (RsSamplerValue)wrapS,
1564 (RsSamplerValue)wrapT,
1565 (RsSamplerValue)wrapR,
1566 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001567}
1568
Jason Samsbba134c2009-06-22 15:49:21 -07001569// ---------------------------------------------------------------------------
1570
Tim Murray460a0492013-11-19 12:45:54 -08001571static jlong
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001572nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) {
Tim Murray71a01b82014-01-07 15:36:19 -08001573 LOG_API("nPathCreate, con(%p)", (RsContext)con);
Jason Samsf15ed012011-10-31 13:23:43 -07001574
Tim Murray3aa89c12014-08-18 17:51:22 -07001575 jlong id = (jlong)(uintptr_t)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic,
Tim Murray460a0492013-11-19 12:45:54 -08001576 (RsAllocation)_vtx,
1577 (RsAllocation)_loop, q);
Jason Samsf15ed012011-10-31 13:23:43 -07001578 return id;
1579}
1580
Tim Murray460a0492013-11-19 12:45:54 -08001581static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001582nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001583{
Tim Murray71a01b82014-01-07 15:36:19 -08001584 LOG_API("nMeshCreate, con(%p)", (RsContext)con);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001585
1586 jint vtxLen = _env->GetArrayLength(_vtx);
Ashok Bhat98071552014-02-12 09:54:43 +00001587 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, NULL);
1588 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
1589 for(int i = 0; i < vtxLen; ++i) {
1590 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
1591 }
1592
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001593 jint idxLen = _env->GetArrayLength(_idx);
Ashok Bhat98071552014-02-12 09:54:43 +00001594 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, NULL);
1595 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
1596 for(int i = 0; i < idxLen; ++i) {
1597 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
1598 }
1599
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001600 jint primLen = _env->GetArrayLength(_prim);
1601 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1602
Tim Murray3aa89c12014-08-18 17:51:22 -07001603 jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001604 (RsAllocation *)vtxPtr, vtxLen,
1605 (RsAllocation *)idxPtr, idxLen,
1606 (uint32_t *)primPtr, primLen);
1607
Ashok Bhat98071552014-02-12 09:54:43 +00001608 free(vtxPtr);
1609 free(idxPtr);
1610 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
1611 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001612 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001613 return id;
1614}
1615
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001616static jint
Tim Murray460a0492013-11-19 12:45:54 -08001617nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001618{
Tim Murray71a01b82014-01-07 15:36:19 -08001619 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001620 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001621 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001622 return vtxCount;
1623}
1624
1625static jint
Tim Murray460a0492013-11-19 12:45:54 -08001626nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001627{
Tim Murray71a01b82014-01-07 15:36:19 -08001628 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001629 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001630 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001631 return idxCount;
1632}
1633
1634static void
Ashok Bhat98071552014-02-12 09:54:43 +00001635nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001636{
Tim Murray71a01b82014-01-07 15:36:19 -08001637 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001638
1639 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08001640 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001641
1642 for(jint i = 0; i < numVtxIDs; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001643 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001644 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001645 }
1646
1647 free(allocs);
1648}
1649
1650static void
Ashok Bhat98071552014-02-12 09:54:43 +00001651nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001652{
Tim Murray71a01b82014-01-07 15:36:19 -08001653 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001654
1655 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1656 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1657
Tim Murrayeff663f2013-11-15 13:08:30 -08001658 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001659
1660 for(jint i = 0; i < numIndices; i ++) {
Tim Murray3aa89c12014-08-18 17:51:22 -07001661 const jlong alloc = (jlong)(uintptr_t)allocs[i];
Ashok Bhat98071552014-02-12 09:54:43 +00001662 const jint prim = (jint)prims[i];
1663 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
1664 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001665 }
1666
1667 free(allocs);
1668 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001669}
1670
Tim Murray56f9e6f2014-05-16 11:47:26 -07001671static jint
1672nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
1673 return (jint)sizeof(void*);
1674}
1675
1676
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001677// ---------------------------------------------------------------------------
1678
Jason Samsd19f10d2009-05-22 14:03:28 -07001679
Jason Sams94d8e90a2009-06-10 16:09:05 -07001680static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001681
1682static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001683{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001684
Tim Murrayeff663f2013-11-15 13:08:30 -08001685{"nDeviceCreate", "()J", (void*)nDeviceCreate },
1686{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
1687{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
1688{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
1689{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
1690{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001691
Tim Murrayeff663f2013-11-15 13:08:30 -08001692{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
1693{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001694
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001695
Jason Sams2e1872f2010-08-17 16:25:41 -07001696// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08001697{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
1698{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
1699{"rsnContextFinish", "(J)V", (void*)nContextFinish },
1700{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
1701{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
1702{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
1703{"rsnContextDump", "(JI)V", (void*)nContextDump },
1704{"rsnContextPause", "(J)V", (void*)nContextPause },
1705{"rsnContextResume", "(J)V", (void*)nContextResume },
1706{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Tim Murray460a0492013-11-19 12:45:54 -08001707{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
1708{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
1709{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001710
Tim Murray460a0492013-11-19 12:45:54 -08001711{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001712{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08001713{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
1714{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
1715{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001716{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001717
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001718{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
1719{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
1720{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001721
Tim Murray460a0492013-11-19 12:45:54 -08001722{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001723{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08001724{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00001725{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001726
Tim Murray460a0492013-11-19 12:45:54 -08001727{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001728{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001729
Ashok Bhat98071552014-02-12 09:54:43 +00001730{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08001731{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
1732{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
1733{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001734
Tim Murray460a0492013-11-19 12:45:54 -08001735{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1736{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08001737
Tim Murray460a0492013-11-19 12:45:54 -08001738{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
1739{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
1740{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
1741{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
1742{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
1743{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
1744{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D },
1745{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
1746{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
1747{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
1748{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
1749{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead },
1750{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D },
1751{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D },
1752{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
1753{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
1754{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001755
Tim Murray460a0492013-11-19 12:45:54 -08001756{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
1757{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
1758{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
1759{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
1760{"rsnScriptForEach", "(JJIJJ)V", (void*)nScriptForEach },
1761{"rsnScriptForEach", "(JJIJJ[B)V", (void*)nScriptForEachV },
1762{"rsnScriptForEachClipped", "(JJIJJIIIIII)V", (void*)nScriptForEachClipped },
1763{"rsnScriptForEachClipped", "(JJIJJ[BIIIIII)V", (void*)nScriptForEachClippedV },
Chris Wailes94961062014-06-11 12:01:28 -07001764{"rsnScriptForEachMultiClipped", "(JJI[JJIIIIII)V", (void*)nScriptForEachMultiClipped },
1765{"rsnScriptForEachMultiClipped", "(JJI[JJ[BIIIIII)V", (void*)nScriptForEachMultiClippedV },
Tim Murray460a0492013-11-19 12:45:54 -08001766{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
1767{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
1768{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
1769{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
1770{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
1771{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
1772{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
1773{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
1774{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
1775{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
1776{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
1777{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001778
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001779{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001780{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
1781{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
1782{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001783{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001784{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
1785{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
1786{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Jason Sams0011bcf2009-12-15 12:58:36 -08001787
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001788{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001789
Tim Murray460a0492013-11-19 12:45:54 -08001790{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
1791{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
1792{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001793
Ashok Bhat98071552014-02-12 09:54:43 +00001794{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001795{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001796{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001797
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001798{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
1799{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
1800{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
1801{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
1802{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001803
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001804{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001805
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001806{"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001807{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001808
Tim Murray460a0492013-11-19 12:45:54 -08001809{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
1810{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00001811{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
1812{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001813
Tim Murray56f9e6f2014-05-16 11:47:26 -07001814{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07001815};
1816
1817static int registerFuncs(JNIEnv *_env)
1818{
1819 return android::AndroidRuntime::registerNativeMethods(
1820 _env, classPathName, methods, NELEM(methods));
1821}
1822
1823// ---------------------------------------------------------------------------
1824
1825jint JNI_OnLoad(JavaVM* vm, void* reserved)
1826{
1827 JNIEnv* env = NULL;
1828 jint result = -1;
1829
Jason Samsd19f10d2009-05-22 14:03:28 -07001830 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001831 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001832 goto bail;
1833 }
1834 assert(env != NULL);
1835
1836 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001837 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001838 goto bail;
1839 }
1840
1841 /* success -- return valid version number */
1842 result = JNI_VERSION_1_4;
1843
1844bail:
1845 return result;
1846}