blob: ae39b05e74d48de0d2a077c71e417c50ee1bfa52 [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 Sams3eaa3382009-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 Sams3eaa3382009-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 Sams3eaa3382009-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 Sams3eaa3382009-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 Sams3eaa3382009-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");
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000225 return (jlong)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");
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000246 return (jlong)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");
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000270 return (jlong)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 Murray460a0492013-11-19 12:45:54 -0800412 return (jlong)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 Murray460a0492013-11-19 12:45:54 -0800438 jlong id = (jlong)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
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000448 return (jlong)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++) {
486 const jlong id = (jlong)ids[i];
487 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 Murray460a0492013-11-19 12:45:54 -0800507 return (jlong)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 ++) {
Ashok Bhat98071552014-02-12 09:54:43 +0000524 const jlong data = (jlong)typeData[i];
525 _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);
Ashok Bhat98071552014-02-12 09:54:43 +0000535 return (jlong) 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 Murray460a0492013-11-19 12:45:54 -0800603 jlong id = (jlong)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 Murray460a0492013-11-19 12:45:54 -0800619 jlong id = (jlong)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 Murray460a0492013-11-19 12:45:54 -0800635 jlong id = (jlong)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 Murray38faea32012-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 Murray460a0492013-11-19 12:45:54 -0800813 return (jlong) 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 Murray460a0492013-11-19 12:45:54 -0800831 jlong id = (jlong)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 Murray460a0492013-11-19 12:45:54 -0800849 jlong id = (jlong)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 Murray460a0492013-11-19 12:45:54 -0800857 jlong id = (jlong)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);
890 jlong id = (jlong)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);
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000901 jlong id = (jlong)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
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000915 jlong id = (jlong)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
Ashok Bhat0e0c0882014-02-04 14:57:58 +0000937 jlong id = (jlong)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 Hinesadeb8092012-04-20 14:26:06 -07001054 (const size_t*) dimsPtr, dimsLen);
1055 _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
Jason Sams22534172009-08-04 16:58:20 -07001154// -----------------------------------
1155
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001156static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001157nScriptCCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Samse4a06c52011-03-16 16:29:28 -07001158 jstring resName, jstring cacheDir,
1159 jbyteArray scriptRef, jint length)
Jason Sams22534172009-08-04 16:58:20 -07001160{
Tim Murray71a01b82014-01-07 15:36:19 -08001161 LOG_API("nScriptCCreate, con(%p)", (RsContext)con);
Jason Sams22534172009-08-04 16:58:20 -07001162
Jason Samse4a06c52011-03-16 16:29:28 -07001163 AutoJavaStringToUTF8 resNameUTF(_env, resName);
1164 AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001165 jlong ret = 0;
Elliott Hughes8451b252011-04-07 19:17:57 -07001166 jbyte* script_ptr = NULL;
Jack Palevich43702d82009-05-28 13:38:16 -07001167 jint _exception = 0;
1168 jint remaining;
Jack Palevich43702d82009-05-28 13:38:16 -07001169 if (!scriptRef) {
1170 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001171 //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
Jack Palevich43702d82009-05-28 13:38:16 -07001172 goto exit;
1173 }
Jack Palevich43702d82009-05-28 13:38:16 -07001174 if (length < 0) {
1175 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001176 //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
Jack Palevich43702d82009-05-28 13:38:16 -07001177 goto exit;
1178 }
Jason Samse4a06c52011-03-16 16:29:28 -07001179 remaining = _env->GetArrayLength(scriptRef);
Jack Palevich43702d82009-05-28 13:38:16 -07001180 if (remaining < length) {
1181 _exception = 1;
Elliott Hughes8451b252011-04-07 19:17:57 -07001182 //jniThrowException(_env, "java/lang/IllegalArgumentException",
1183 // "length > script.length - offset");
Jack Palevich43702d82009-05-28 13:38:16 -07001184 goto exit;
1185 }
Jason Samse4a06c52011-03-16 16:29:28 -07001186 script_ptr = (jbyte *)
Jack Palevich43702d82009-05-28 13:38:16 -07001187 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
Jack Palevich43702d82009-05-28 13:38:16 -07001188
Tim Murrayeff663f2013-11-15 13:08:30 -08001189 //rsScriptCSetText((RsContext)con, (const char *)script_ptr, length);
Jason Samse4a06c52011-03-16 16:29:28 -07001190
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001191 ret = (jlong)rsScriptCCreate((RsContext)con,
Alex Sakhartchouke7c4a752011-04-06 10:57:51 -07001192 resNameUTF.c_str(), resNameUTF.length(),
1193 cacheDirUTF.c_str(), cacheDirUTF.length(),
Jason Samse4a06c52011-03-16 16:29:28 -07001194 (const char *)script_ptr, length);
Jason Sams39ddc9502009-06-05 17:35:09 -07001195
Jack Palevich43702d82009-05-28 13:38:16 -07001196exit:
Jason Samse4a06c52011-03-16 16:29:28 -07001197 if (script_ptr) {
1198 _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
Jack Palevich43702d82009-05-28 13:38:16 -07001199 _exception ? JNI_ABORT: 0);
1200 }
Jason Samsd19f10d2009-05-22 14:03:28 -07001201
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001202 return (jlong)ret;
Jason Samsd19f10d2009-05-22 14:03:28 -07001203}
1204
Tim Murray460a0492013-11-19 12:45:54 -08001205static jlong
1206nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid)
Jason Sams6ab97682012-08-10 12:09:43 -07001207{
Tim Murray71a01b82014-01-07 15:36:19 -08001208 LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id, (void *)eid);
Tim Murray460a0492013-11-19 12:45:54 -08001209 return (jlong)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid);
Jason Sams6ab97682012-08-10 12:09:43 -07001210}
1211
Tim Murray460a0492013-11-19 12:45:54 -08001212static jlong
1213nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig)
Jason Sams08a81582012-09-18 12:32:10 -07001214{
Tim Murray71a01b82014-01-07 15:36:19 -08001215 LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con, (void *)sid, slot, sig);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001216 return (jlong)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -07001217}
1218
Tim Murray460a0492013-11-19 12:45:54 -08001219static jlong
1220nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot)
Jason Sams08a81582012-09-18 12:32:10 -07001221{
Tim Murray71a01b82014-01-07 15:36:19 -08001222 LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid, slot);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001223 return (jlong)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot);
Jason Sams08a81582012-09-18 12:32:10 -07001224}
1225
Tim Murray460a0492013-11-19 12:45:54 -08001226static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001227nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src,
1228 jlongArray _dstk, jlongArray _dstf, jlongArray _types)
Jason Sams08a81582012-09-18 12:32:10 -07001229{
Tim Murray71a01b82014-01-07 15:36:19 -08001230 LOG_API("nScriptGroupCreate, con(%p)", (RsContext)con);
Jason Sams08a81582012-09-18 12:32:10 -07001231
Ashok Bhat98071552014-02-12 09:54:43 +00001232 jint kernelsLen = _env->GetArrayLength(_kernels);
1233 jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, NULL);
1234 RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen);
1235 for(int i = 0; i < kernelsLen; ++i) {
1236 kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i];
1237 }
Jason Sams08a81582012-09-18 12:32:10 -07001238
Ashok Bhat98071552014-02-12 09:54:43 +00001239 jint srcLen = _env->GetArrayLength(_src);
1240 jlong *jSrcPtr = _env->GetLongArrayElements(_src, NULL);
1241 RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen);
1242 for(int i = 0; i < srcLen; ++i) {
1243 srcPtr[i] = (RsScriptKernelID)jSrcPtr[i];
1244 }
Jason Sams08a81582012-09-18 12:32:10 -07001245
Ashok Bhat98071552014-02-12 09:54:43 +00001246 jint dstkLen = _env->GetArrayLength(_dstk);
1247 jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, NULL);
1248 RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen);
1249 for(int i = 0; i < dstkLen; ++i) {
1250 dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i];
1251 }
1252
1253 jint dstfLen = _env->GetArrayLength(_dstf);
1254 jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, NULL);
1255 RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen);
1256 for(int i = 0; i < dstfLen; ++i) {
1257 dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i];
1258 }
1259
1260 jint typesLen = _env->GetArrayLength(_types);
1261 jlong *jTypesPtr = _env->GetLongArrayElements(_types, NULL);
1262 RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen);
1263 for(int i = 0; i < typesLen; ++i) {
1264 typesPtr[i] = (RsType)jTypesPtr[i];
1265 }
1266
1267 jlong id = (jlong)rsScriptGroupCreate((RsContext)con,
1268 (RsScriptKernelID *)kernelsPtr, kernelsLen * sizeof(RsScriptKernelID),
1269 (RsScriptKernelID *)srcPtr, srcLen * sizeof(RsScriptKernelID),
1270 (RsScriptKernelID *)dstkPtr, dstkLen * sizeof(RsScriptKernelID),
1271 (RsScriptFieldID *)dstfPtr, dstfLen * sizeof(RsScriptKernelID),
1272 (RsType *)typesPtr, typesLen * sizeof(RsType));
1273
1274 free(kernelsPtr);
1275 free(srcPtr);
1276 free(dstkPtr);
1277 free(dstfPtr);
1278 free(typesPtr);
1279 _env->ReleaseLongArrayElements(_kernels, jKernelsPtr, 0);
1280 _env->ReleaseLongArrayElements(_src, jSrcPtr, 0);
1281 _env->ReleaseLongArrayElements(_dstk, jDstkPtr, 0);
1282 _env->ReleaseLongArrayElements(_dstf, jDstfPtr, 0);
1283 _env->ReleaseLongArrayElements(_types, jTypesPtr, 0);
Jason Sams08a81582012-09-18 12:32:10 -07001284 return id;
1285}
1286
1287static void
Tim Murray460a0492013-11-19 12:45:54 -08001288nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001289{
Tim Murray71a01b82014-01-07 15:36:19 -08001290 LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
Jason Sams08a81582012-09-18 12:32:10 -07001291 (void *)gid, (void *)kid, (void *)alloc);
Tim Murrayeff663f2013-11-15 13:08:30 -08001292 rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001293}
1294
1295static void
Tim Murray460a0492013-11-19 12:45:54 -08001296nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc)
Jason Sams08a81582012-09-18 12:32:10 -07001297{
Tim Murray71a01b82014-01-07 15:36:19 -08001298 LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con,
Jason Sams08a81582012-09-18 12:32:10 -07001299 (void *)gid, (void *)kid, (void *)alloc);
Tim Murrayeff663f2013-11-15 13:08:30 -08001300 rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
Jason Sams08a81582012-09-18 12:32:10 -07001301}
1302
1303static void
Tim Murray460a0492013-11-19 12:45:54 -08001304nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid)
Jason Sams08a81582012-09-18 12:32:10 -07001305{
Tim Murray71a01b82014-01-07 15:36:19 -08001306 LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid);
Tim Murrayeff663f2013-11-15 13:08:30 -08001307 rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid);
Jason Sams08a81582012-09-18 12:32:10 -07001308}
1309
Jason Samsd19f10d2009-05-22 14:03:28 -07001310// ---------------------------------------------------------------------------
1311
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001312static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001313nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con,
Jason Sams331bf9b2011-04-06 11:23:54 -07001314 jboolean colorMaskR, jboolean colorMaskG, jboolean colorMaskB, jboolean colorMaskA,
1315 jboolean depthMask, jboolean ditherEnable,
1316 jint srcFunc, jint destFunc,
1317 jint depthFunc)
Jason Samsd19f10d2009-05-22 14:03:28 -07001318{
Tim Murray71a01b82014-01-07 15:36:19 -08001319 LOG_API("nProgramStoreCreate, con(%p)", (RsContext)con);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001320 return (jlong)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA,
Jason Sams331bf9b2011-04-06 11:23:54 -07001321 depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc,
1322 (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc);
Jason Samsd19f10d2009-05-22 14:03:28 -07001323}
1324
Jason Sams0011bcf2009-12-15 12:58:36 -08001325// ---------------------------------------------------------------------------
1326
1327static void
Tim Murray460a0492013-11-19 12:45:54 -08001328nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a)
Jason Sams0011bcf2009-12-15 12:58:36 -08001329{
Tim Murray71a01b82014-01-07 15:36:19 -08001330 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 -08001331 rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a);
Jason Sams0011bcf2009-12-15 12:58:36 -08001332}
Jason Sams54c0ec12009-11-30 14:49:55 -08001333
Jason Sams68afd012009-12-17 16:55:08 -08001334static void
Tim Murray460a0492013-11-19 12:45:54 -08001335nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001336{
Tim Murray71a01b82014-01-07 15:36:19 -08001337 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 -08001338 rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a);
Jason Sams68afd012009-12-17 16:55:08 -08001339}
1340
1341static void
Tim Murray460a0492013-11-19 12:45:54 -08001342nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a)
Jason Sams68afd012009-12-17 16:55:08 -08001343{
Tim Murray71a01b82014-01-07 15:36:19 -08001344 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 -08001345 rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a);
Jason Sams68afd012009-12-17 16:55:08 -08001346}
1347
Jason Samsd19f10d2009-05-22 14:03:28 -07001348// ---------------------------------------------------------------------------
1349
Tim Murray460a0492013-11-19 12:45:54 -08001350static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001351nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001352 jobjectArray texNames, jlongArray params)
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001353{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001354 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Ashok Bhat98071552014-02-12 09:54:43 +00001355 jlong *jParamPtr = _env->GetLongArrayElements(params, NULL);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001356 jint paramLen = _env->GetArrayLength(params);
1357
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001358 int texCount = _env->GetArrayLength(texNames);
1359 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1360 const char ** nameArray = names.c_str();
1361 size_t* sizeArray = names.c_str_len();
1362
Tim Murray71a01b82014-01-07 15:36:19 -08001363 LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001364
Ashok Bhat98071552014-02-12 09:54:43 +00001365 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1366 for(int i = 0; i < paramLen; ++i) {
1367 paramPtr[i] = (uintptr_t)jParamPtr[i];
1368 }
Tim Murray460a0492013-11-19 12:45:54 -08001369 jlong ret = (jlong)rsProgramFragmentCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001370 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001371 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001372
Ashok Bhat98071552014-02-12 09:54:43 +00001373 free(paramPtr);
1374 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams7e5ab3b2009-12-15 13:27:04 -08001375 return ret;
1376}
1377
1378
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001379// ---------------------------------------------------------------------------
1380
Tim Murray460a0492013-11-19 12:45:54 -08001381static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001382nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader,
Ashok Bhat98071552014-02-12 09:54:43 +00001383 jobjectArray texNames, jlongArray params)
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001384{
Alex Sakhartchoukb0253ea2011-01-07 11:12:08 -08001385 AutoJavaStringToUTF8 shaderUTF(_env, shader);
Ashok Bhat98071552014-02-12 09:54:43 +00001386 jlong *jParamPtr = _env->GetLongArrayElements(params, NULL);
Jason Sams0011bcf2009-12-15 12:58:36 -08001387 jint paramLen = _env->GetArrayLength(params);
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001388
Tim Murray71a01b82014-01-07 15:36:19 -08001389 LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen);
Jason Sams0011bcf2009-12-15 12:58:36 -08001390
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001391 int texCount = _env->GetArrayLength(texNames);
1392 AutoJavaStringArrayToUTF8 names(_env, texNames, texCount);
1393 const char ** nameArray = names.c_str();
1394 size_t* sizeArray = names.c_str_len();
1395
Ashok Bhat98071552014-02-12 09:54:43 +00001396 uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen);
1397 for(int i = 0; i < paramLen; ++i) {
1398 paramPtr[i] = (uintptr_t)jParamPtr[i];
1399 }
1400
Tim Murray460a0492013-11-19 12:45:54 -08001401 jlong ret = (jlong)rsProgramVertexCreate((RsContext)con, shaderUTF.c_str(), shaderUTF.length(),
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001402 nameArray, texCount, sizeArray,
Ashok Bhat98071552014-02-12 09:54:43 +00001403 paramPtr, paramLen);
Alex Sakhartchouk2123b462012-02-15 16:21:46 -08001404
Ashok Bhat98071552014-02-12 09:54:43 +00001405 free(paramPtr);
1406 _env->ReleaseLongArrayElements(params, jParamPtr, JNI_ABORT);
Jason Sams0011bcf2009-12-15 12:58:36 -08001407 return ret;
1408}
Jason Sams1fe9b8c2009-06-11 14:46:10 -07001409
Jason Samsebfb4362009-09-23 13:57:02 -07001410// ---------------------------------------------------------------------------
1411
Tim Murray460a0492013-11-19 12:45:54 -08001412static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001413nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull)
Jason Samsebfb4362009-09-23 13:57:02 -07001414{
Tim Murray71a01b82014-01-07 15:36:19 -08001415 LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con, pointSprite, cull);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001416 return (jlong)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull);
Jason Samsebfb4362009-09-23 13:57:02 -07001417}
1418
Jason Samsd19f10d2009-05-22 14:03:28 -07001419
1420// ---------------------------------------------------------------------------
1421
1422static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001423nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script)
Jason Samsd19f10d2009-05-22 14:03:28 -07001424{
Tim Murray71a01b82014-01-07 15:36:19 -08001425 LOG_API("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script);
Tim Murrayeff663f2013-11-15 13:08:30 -08001426 rsContextBindRootScript((RsContext)con, (RsScript)script);
Jason Samsd19f10d2009-05-22 14:03:28 -07001427}
1428
1429static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001430nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs)
Jason Samsd19f10d2009-05-22 14:03:28 -07001431{
Tim Murray71a01b82014-01-07 15:36:19 -08001432 LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs);
Tim Murrayeff663f2013-11-15 13:08:30 -08001433 rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs);
Jason Samsd19f10d2009-05-22 14:03:28 -07001434}
1435
1436static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001437nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsd19f10d2009-05-22 14:03:28 -07001438{
Tim Murray71a01b82014-01-07 15:36:19 -08001439 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con, (RsProgramFragment)pf);
Tim Murrayeff663f2013-11-15 13:08:30 -08001440 rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf);
Jason Samsd19f10d2009-05-22 14:03:28 -07001441}
1442
Jason Sams0826a6f2009-06-15 19:04:56 -07001443static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001444nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Sams0826a6f2009-06-15 19:04:56 -07001445{
Tim Murray71a01b82014-01-07 15:36:19 -08001446 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf);
Tim Murrayeff663f2013-11-15 13:08:30 -08001447 rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf);
Jason Sams0826a6f2009-06-15 19:04:56 -07001448}
1449
Joe Onoratod7b37742009-08-09 22:57:44 -07001450static void
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001451nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf)
Jason Samsebfb4362009-09-23 13:57:02 -07001452{
Tim Murray71a01b82014-01-07 15:36:19 -08001453 LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf);
Tim Murrayeff663f2013-11-15 13:08:30 -08001454 rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf);
Jason Samsebfb4362009-09-23 13:57:02 -07001455}
1456
Joe Onoratod7b37742009-08-09 22:57:44 -07001457
Jason Sams02fb2cb2009-05-28 15:37:57 -07001458// ---------------------------------------------------------------------------
1459
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001460static jlong
Tim Murrayeff663f2013-11-15 13:08:30 -08001461nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001462 jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
Jason Sams02fb2cb2009-05-28 15:37:57 -07001463{
Tim Murray71a01b82014-01-07 15:36:19 -08001464 LOG_API("nSamplerCreate, con(%p)", (RsContext)con);
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001465 return (jlong)rsSamplerCreate((RsContext)con,
Alex Sakhartchouka89094a2011-05-04 17:45:36 -07001466 (RsSamplerValue)magFilter,
1467 (RsSamplerValue)minFilter,
1468 (RsSamplerValue)wrapS,
1469 (RsSamplerValue)wrapT,
1470 (RsSamplerValue)wrapR,
1471 aniso);
Jason Sams02fb2cb2009-05-28 15:37:57 -07001472}
1473
Jason Samsbba134c2009-06-22 15:49:21 -07001474// ---------------------------------------------------------------------------
1475
Tim Murray460a0492013-11-19 12:45:54 -08001476static jlong
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001477nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) {
Tim Murray71a01b82014-01-07 15:36:19 -08001478 LOG_API("nPathCreate, con(%p)", (RsContext)con);
Jason Samsf15ed012011-10-31 13:23:43 -07001479
Tim Murray460a0492013-11-19 12:45:54 -08001480 jlong id = (jlong)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic,
1481 (RsAllocation)_vtx,
1482 (RsAllocation)_loop, q);
Jason Samsf15ed012011-10-31 13:23:43 -07001483 return id;
1484}
1485
Tim Murray460a0492013-11-19 12:45:54 -08001486static jlong
Ashok Bhat98071552014-02-12 09:54:43 +00001487nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim)
Jason Samsbba134c2009-06-22 15:49:21 -07001488{
Tim Murray71a01b82014-01-07 15:36:19 -08001489 LOG_API("nMeshCreate, con(%p)", (RsContext)con);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001490
1491 jint vtxLen = _env->GetArrayLength(_vtx);
Ashok Bhat98071552014-02-12 09:54:43 +00001492 jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, NULL);
1493 RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen);
1494 for(int i = 0; i < vtxLen; ++i) {
1495 vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i];
1496 }
1497
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001498 jint idxLen = _env->GetArrayLength(_idx);
Ashok Bhat98071552014-02-12 09:54:43 +00001499 jlong *jIdxPtr = _env->GetLongArrayElements(_idx, NULL);
1500 RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen);
1501 for(int i = 0; i < idxLen; ++i) {
1502 idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i];
1503 }
1504
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001505 jint primLen = _env->GetArrayLength(_prim);
1506 jint *primPtr = _env->GetIntArrayElements(_prim, NULL);
1507
Ashok Bhat98071552014-02-12 09:54:43 +00001508 jlong id = (jlong)rsMeshCreate((RsContext)con,
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001509 (RsAllocation *)vtxPtr, vtxLen,
1510 (RsAllocation *)idxPtr, idxLen,
1511 (uint32_t *)primPtr, primLen);
1512
Ashok Bhat98071552014-02-12 09:54:43 +00001513 free(vtxPtr);
1514 free(idxPtr);
1515 _env->ReleaseLongArrayElements(_vtx, jVtxPtr, 0);
1516 _env->ReleaseLongArrayElements(_idx, jIdxPtr, 0);
Alex Sakhartchouk25999a02011-05-12 10:38:03 -07001517 _env->ReleaseIntArrayElements(_prim, primPtr, 0);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001518 return id;
1519}
1520
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001521static jint
Tim Murray460a0492013-11-19 12:45:54 -08001522nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001523{
Tim Murray71a01b82014-01-07 15:36:19 -08001524 LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001525 jint vtxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001526 rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001527 return vtxCount;
1528}
1529
1530static jint
Tim Murray460a0492013-11-19 12:45:54 -08001531nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001532{
Tim Murray71a01b82014-01-07 15:36:19 -08001533 LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001534 jint idxCount = 0;
Tim Murrayeff663f2013-11-15 13:08:30 -08001535 rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001536 return idxCount;
1537}
1538
1539static void
Ashok Bhat98071552014-02-12 09:54:43 +00001540nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001541{
Tim Murray71a01b82014-01-07 15:36:19 -08001542 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001543
1544 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation));
Tim Murrayeff663f2013-11-15 13:08:30 -08001545 rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001546
1547 for(jint i = 0; i < numVtxIDs; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +00001548 const jlong alloc = (jlong)allocs[i];
1549 _env->SetLongArrayRegion(_ids, i, 1, &alloc);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001550 }
1551
1552 free(allocs);
1553}
1554
1555static void
Ashok Bhat98071552014-02-12 09:54:43 +00001556nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices)
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001557{
Tim Murray71a01b82014-01-07 15:36:19 -08001558 LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001559
1560 RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation));
1561 uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t));
1562
Tim Murrayeff663f2013-11-15 13:08:30 -08001563 rsaMeshGetIndices((RsContext)con, (RsMesh)mesh, allocs, prims, (uint32_t)numIndices);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001564
1565 for(jint i = 0; i < numIndices; i ++) {
Ashok Bhat98071552014-02-12 09:54:43 +00001566 const jlong alloc = (jlong)allocs[i];
1567 const jint prim = (jint)prims[i];
1568 _env->SetLongArrayRegion(_idxIds, i, 1, &alloc);
1569 _env->SetIntArrayRegion(_primitives, i, 1, &prim);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001570 }
1571
1572 free(allocs);
1573 free(prims);
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001574}
1575
Tim Murray56f9e6f2014-05-16 11:47:26 -07001576static jint
1577nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
1578 return (jint)sizeof(void*);
1579}
1580
1581
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001582// ---------------------------------------------------------------------------
1583
Jason Samsd19f10d2009-05-22 14:03:28 -07001584
Jason Sams94d8e90a2009-06-10 16:09:05 -07001585static const char *classPathName = "android/renderscript/RenderScript";
Jason Samsd19f10d2009-05-22 14:03:28 -07001586
1587static JNINativeMethod methods[] = {
Jason Sams1c415172010-11-08 17:06:46 -08001588{"_nInit", "()V", (void*)_nInit },
Jason Samsea84a7c2009-09-04 14:42:41 -07001589
Tim Murrayeff663f2013-11-15 13:08:30 -08001590{"nDeviceCreate", "()J", (void*)nDeviceCreate },
1591{"nDeviceDestroy", "(J)V", (void*)nDeviceDestroy },
1592{"nDeviceSetConfig", "(JII)V", (void*)nDeviceSetConfig },
1593{"nContextGetUserMessage", "(J[I)I", (void*)nContextGetUserMessage },
1594{"nContextGetErrorMessage", "(J)Ljava/lang/String;", (void*)nContextGetErrorMessage },
1595{"nContextPeekMessage", "(J[I)I", (void*)nContextPeekMessage },
Jason Sams1c415172010-11-08 17:06:46 -08001596
Tim Murrayeff663f2013-11-15 13:08:30 -08001597{"nContextInitToClient", "(J)V", (void*)nContextInitToClient },
1598{"nContextDeinitToClient", "(J)V", (void*)nContextDeinitToClient },
Jason Samsd19f10d2009-05-22 14:03:28 -07001599
Alex Sakhartchouk9b949fc2010-06-24 17:15:34 -07001600
Jason Sams2e1872f2010-08-17 16:25:41 -07001601// All methods below are thread protected in java.
Tim Murrayeff663f2013-11-15 13:08:30 -08001602{"rsnContextCreate", "(JIII)J", (void*)nContextCreate },
1603{"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL },
1604{"rsnContextFinish", "(J)V", (void*)nContextFinish },
1605{"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority },
1606{"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface },
1607{"rsnContextDestroy", "(J)V", (void*)nContextDestroy },
1608{"rsnContextDump", "(JI)V", (void*)nContextDump },
1609{"rsnContextPause", "(J)V", (void*)nContextPause },
1610{"rsnContextResume", "(J)V", (void*)nContextResume },
1611{"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage },
Tim Murray460a0492013-11-19 12:45:54 -08001612{"rsnAssignName", "(JJ[B)V", (void*)nAssignName },
1613{"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName },
1614{"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy },
Jason Sams64676f32009-07-08 18:01:53 -07001615
Tim Murray460a0492013-11-19 12:45:54 -08001616{"rsnFileA3DCreateFromFile", "(JLjava/lang/String;)J", (void*)nFileA3DCreateFromFile },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001617{"rsnFileA3DCreateFromAssetStream", "(JJ)J", (void*)nFileA3DCreateFromAssetStream },
Tim Murray460a0492013-11-19 12:45:54 -08001618{"rsnFileA3DCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;)J", (void*)nFileA3DCreateFromAsset },
1619{"rsnFileA3DGetNumIndexEntries", "(JJ)I", (void*)nFileA3DGetNumIndexEntries },
1620{"rsnFileA3DGetIndexEntries", "(JJI[I[Ljava/lang/String;)V", (void*)nFileA3DGetIndexEntries },
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001621{"rsnFileA3DGetEntryByIndex", "(JJI)J", (void*)nFileA3DGetEntryByIndex },
Jason Samsd19f10d2009-05-22 14:03:28 -07001622
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001623{"rsnFontCreateFromFile", "(JLjava/lang/String;FI)J", (void*)nFontCreateFromFile },
1624{"rsnFontCreateFromAssetStream", "(JLjava/lang/String;FIJ)J", (void*)nFontCreateFromAssetStream },
1625{"rsnFontCreateFromAsset", "(JLandroid/content/res/AssetManager;Ljava/lang/String;FI)J", (void*)nFontCreateFromAsset },
Jason Samsd19f10d2009-05-22 14:03:28 -07001626
Tim Murray460a0492013-11-19 12:45:54 -08001627{"rsnElementCreate", "(JJIZI)J", (void*)nElementCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001628{"rsnElementCreate2", "(J[J[Ljava/lang/String;[I)J", (void*)nElementCreate2 },
Tim Murray460a0492013-11-19 12:45:54 -08001629{"rsnElementGetNativeData", "(JJ[I)V", (void*)nElementGetNativeData },
Ashok Bhat98071552014-02-12 09:54:43 +00001630{"rsnElementGetSubElements", "(JJ[J[Ljava/lang/String;[I)V", (void*)nElementGetSubElements },
Jason Samsd19f10d2009-05-22 14:03:28 -07001631
Tim Murray460a0492013-11-19 12:45:54 -08001632{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001633{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },
Jason Samsd19f10d2009-05-22 14:03:28 -07001634
Ashok Bhat98071552014-02-12 09:54:43 +00001635{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
Tim Murray460a0492013-11-19 12:45:54 -08001636{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
1637{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
1638{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
Jason Sams5476b452010-12-08 16:14:36 -08001639
Tim Murray460a0492013-11-19 12:45:54 -08001640{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
1641{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
Jason Sams4ef66502010-12-10 16:03:15 -08001642
Tim Murray460a0492013-11-19 12:45:54 -08001643{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
1644{"rsnAllocationGetSurface", "(JJ)Landroid/view/Surface;", (void*)nAllocationGetSurface },
1645{"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface },
1646{"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend },
1647{"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive },
1648{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D },
1649{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D },
1650{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D },
1651{"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc },
1652{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D },
1653{"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc },
1654{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead },
1655{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D },
1656{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D },
1657{"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType},
1658{"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D },
1659{"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps },
Jason Samsbd1c3ad2009-08-03 16:03:08 -07001660
Tim Murray460a0492013-11-19 12:45:54 -08001661{"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation },
1662{"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone },
1663{"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke },
1664{"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV },
1665{"rsnScriptForEach", "(JJIJJ)V", (void*)nScriptForEach },
1666{"rsnScriptForEach", "(JJIJJ[B)V", (void*)nScriptForEachV },
1667{"rsnScriptForEachClipped", "(JJIJJIIIIII)V", (void*)nScriptForEachClipped },
1668{"rsnScriptForEachClipped", "(JJIJJ[BIIIIII)V", (void*)nScriptForEachClippedV },
1669{"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI },
1670{"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI },
1671{"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ },
1672{"rsnScriptGetVarJ", "(JJI)J", (void*)nScriptGetVarJ },
1673{"rsnScriptSetVarF", "(JJIF)V", (void*)nScriptSetVarF },
1674{"rsnScriptGetVarF", "(JJI)F", (void*)nScriptGetVarF },
1675{"rsnScriptSetVarD", "(JJID)V", (void*)nScriptSetVarD },
1676{"rsnScriptGetVarD", "(JJI)D", (void*)nScriptGetVarD },
1677{"rsnScriptSetVarV", "(JJI[B)V", (void*)nScriptSetVarV },
1678{"rsnScriptGetVarV", "(JJI[B)V", (void*)nScriptGetVarV },
1679{"rsnScriptSetVarVE", "(JJI[BJ[I)V", (void*)nScriptSetVarVE },
1680{"rsnScriptSetVarObj", "(JJIJ)V", (void*)nScriptSetVarObj },
Jason Samsd19f10d2009-05-22 14:03:28 -07001681
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001682{"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001683{"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate },
1684{"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate },
1685{"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001686{"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001687{"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput },
1688{"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput },
1689{"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute },
Jason Sams0011bcf2009-12-15 12:58:36 -08001690
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001691{"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001692
Tim Murray460a0492013-11-19 12:45:54 -08001693{"rsnProgramBindConstants", "(JJIJ)V", (void*)nProgramBindConstants },
1694{"rsnProgramBindTexture", "(JJIJ)V", (void*)nProgramBindTexture },
1695{"rsnProgramBindSampler", "(JJIJ)V", (void*)nProgramBindSampler },
Jason Samsebfb4362009-09-23 13:57:02 -07001696
Ashok Bhat98071552014-02-12 09:54:43 +00001697{"rsnProgramFragmentCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramFragmentCreate },
Tim Murray460a0492013-11-19 12:45:54 -08001698{"rsnProgramRasterCreate", "(JZI)J", (void*)nProgramRasterCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001699{"rsnProgramVertexCreate", "(JLjava/lang/String;[Ljava/lang/String;[J)J", (void*)nProgramVertexCreate },
Jason Samsd19f10d2009-05-22 14:03:28 -07001700
Narayan Kamath78c0ce52014-03-19 10:15:51 +00001701{"rsnContextBindRootScript", "(JJ)V", (void*)nContextBindRootScript },
1702{"rsnContextBindProgramStore", "(JJ)V", (void*)nContextBindProgramStore },
1703{"rsnContextBindProgramFragment", "(JJ)V", (void*)nContextBindProgramFragment },
1704{"rsnContextBindProgramVertex", "(JJ)V", (void*)nContextBindProgramVertex },
1705{"rsnContextBindProgramRaster", "(JJ)V", (void*)nContextBindProgramRaster },
Jason Sams02fb2cb2009-05-28 15:37:57 -07001706
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001707{"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate },
Alex Sakhartchouk164aaed2010-07-01 16:14:06 -07001708
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001709{"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate },
Ashok Bhat98071552014-02-12 09:54:43 +00001710{"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate },
Jason Sams2e1872f2010-08-17 16:25:41 -07001711
Tim Murray460a0492013-11-19 12:45:54 -08001712{"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount },
1713{"rsnMeshGetIndexCount", "(JJ)I", (void*)nMeshGetIndexCount },
Ashok Bhat98071552014-02-12 09:54:43 +00001714{"rsnMeshGetVertices", "(JJ[JI)V", (void*)nMeshGetVertices },
1715{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -07001716
Tim Murray56f9e6f2014-05-16 11:47:26 -07001717{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
Jason Samsd19f10d2009-05-22 14:03:28 -07001718};
1719
1720static int registerFuncs(JNIEnv *_env)
1721{
1722 return android::AndroidRuntime::registerNativeMethods(
1723 _env, classPathName, methods, NELEM(methods));
1724}
1725
1726// ---------------------------------------------------------------------------
1727
1728jint JNI_OnLoad(JavaVM* vm, void* reserved)
1729{
1730 JNIEnv* env = NULL;
1731 jint result = -1;
1732
Jason Samsd19f10d2009-05-22 14:03:28 -07001733 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
Steve Block3762c312012-01-06 19:20:56 +00001734 ALOGE("ERROR: GetEnv failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001735 goto bail;
1736 }
1737 assert(env != NULL);
1738
1739 if (registerFuncs(env) < 0) {
Ashok Bhat0e0c0882014-02-04 14:57:58 +00001740 ALOGE("ERROR: Renderscript native registration failed\n");
Jason Samsd19f10d2009-05-22 14:03:28 -07001741 goto bail;
1742 }
1743
1744 /* success -- return valid version number */
1745 result = JNI_VERSION_1_4;
1746
1747bail:
1748 return result;
1749}