android_renderscript_RenderScript.cpp revision 257cecb5e24c9af71ba4d621887e88e46b0ac411
1c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main/*
2c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main * Copyright (C) 2011-2012 The Android Open Source Project
3c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main *
4c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main * Licensed under the Apache License, Version 2.0 (the "License");
5c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main * you may not use this file except in compliance with the License.
6c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main * You may obtain a copy of the License at
7c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main *
8c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main *      http://www.apache.org/licenses/LICENSE-2.0
9c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main *
10c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main * Unless required by applicable law or agreed to in writing, software
11c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main * distributed under the License is distributed on an "AS IS" BASIS,
12c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main * See the License for the specific language governing permissions and
14c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main * limitations under the License.
15c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main */
16c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
17c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main#define LOG_TAG "libRS_jni"
18c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
19c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main#include <stdlib.h>
20c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main#include <stdio.h>
21c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main#include <fcntl.h>
22c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main#include <unistd.h>
23c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main#include <math.h>
24c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main#include <android/bitmap.h>
25257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines#include <android/log.h>
26c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main#include "jni.h"
27c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main#include <rs.h>
28c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main#include <rsEnv.h>
29c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
30c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main//#define LOG_API ALOG
31c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main#define LOG_API(...)
32c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
33257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines#define NELEM(m) (sizeof(m) / sizeof((m)[0]))
34c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
35c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainclass AutoJavaStringToUTF8 {
36c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainpublic:
37c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) {
38c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        fCStr = env->GetStringUTFChars(str, NULL);
39c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        fLength = env->GetStringUTFLength(str);
40c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
41c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    ~AutoJavaStringToUTF8() {
42c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        fEnv->ReleaseStringUTFChars(fJStr, fCStr);
43c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
44c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    const char* c_str() const { return fCStr; }
45c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jsize length() const { return fLength; }
46c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
47c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainprivate:
48c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    JNIEnv*     fEnv;
49c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jstring     fJStr;
50c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    const char* fCStr;
51c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jsize       fLength;
52c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main};
53c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
54c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainclass AutoJavaStringArrayToUTF8 {
55c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainpublic:
56c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength)
57c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    : mEnv(env), mStrings(strings), mStringsLength(stringsLength) {
58c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        mCStrings = NULL;
59c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        mSizeArray = NULL;
60c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        if (stringsLength > 0) {
61c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            mCStrings = (const char **)calloc(stringsLength, sizeof(char *));
62c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t));
63c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            for (jsize ct = 0; ct < stringsLength; ct ++) {
64c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
65c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL);
66c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                mSizeArray[ct] = mEnv->GetStringUTFLength(s);
67c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            }
68c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        }
69c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
70c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    ~AutoJavaStringArrayToUTF8() {
71c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        for (jsize ct=0; ct < mStringsLength; ct++) {
72c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct);
73c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            mEnv->ReleaseStringUTFChars(s, mCStrings[ct]);
74c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        }
75c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        free(mCStrings);
76c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        free(mSizeArray);
77c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
78c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    const char **c_str() const { return mCStrings; }
79c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    size_t *c_str_len() const { return mSizeArray; }
80c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jsize length() const { return mStringsLength; }
81c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
82c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainprivate:
83c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    JNIEnv      *mEnv;
84c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jobjectArray mStrings;
85c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    const char **mCStrings;
86c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    size_t      *mSizeArray;
87c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jsize        mStringsLength;
88c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main};
89c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
90c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main// ---------------------------------------------------------------------------
91c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
92c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
93c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnContextFinish(JNIEnv *_env, jobject _this, RsContext con)
94c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
95c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nContextFinish, con(%p)", con);
96c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsContextFinish(con);
97c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
98c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
99c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
100c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj)
101c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
102c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj);
103c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsObjDestroy(con, (void *)obj);
104c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
105c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
106c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main// ---------------------------------------------------------------------------
107c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
108c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
109c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnDeviceCreate(JNIEnv *_env, jobject _this)
110c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
111c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nDeviceCreate");
112c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return (jint)rsDeviceCreate();
113c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
114c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
115c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
116c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnDeviceDestroy(JNIEnv *_env, jobject _this, jint dev)
117c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
118c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nDeviceDestroy");
119c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return rsDeviceDestroy((RsDevice)dev);
120c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
121c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
122c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
123c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value)
124c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
125c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nDeviceSetConfig  dev(%p), param(%i), value(%i)", (void *)dev, p, value);
126c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value);
127c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
128c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
129c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
130c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer, jint ct)
131c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
132c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nContextCreate");
133c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer, (RsContextType)ct, false, false);
134c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
135c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
136c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
137c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
138c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p)
139c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
140c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p);
141c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsContextSetPriority(con, p);
142c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
143c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
144c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
145c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
146c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
147c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnContextDestroy(JNIEnv *_env, jobject _this, RsContext con)
148c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
149c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nContextDestroy, con(%p)", con);
150c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsContextDestroy(con);
151c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
152c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
153c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
154c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits)
155c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
156c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nContextDump, con(%p)  bits(%i)", (RsContext)con, bits);
157c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsContextDump((RsContext)con, bits);
158c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
159c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
160c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
161c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jstring
162c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con)
163c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
164c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nContextGetErrorMessage, con(%p)", con);
165c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    char buf[1024];
166c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
167c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    size_t receiveLen;
168c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    uint32_t subID;
169c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    int id = rsContextGetMessage(con,
170c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                 buf, sizeof(buf),
171c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                 &receiveLen, sizeof(receiveLen),
172c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                 &subID, sizeof(subID));
173c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    if (!id && receiveLen) {
174257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines        __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG,
175257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines            "message receive buffer too small.  %zu", receiveLen);
176c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
177c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return _env->NewStringUTF(buf);
178c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
179c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
180c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
181c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data)
182c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
183c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
184c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nContextGetMessage, con(%p), len(%i)", con, len);
185c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *ptr = _env->GetIntArrayElements(data, NULL);
186c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    size_t receiveLen;
187c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    uint32_t subID;
188c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    int id = rsContextGetMessage(con,
189c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                 ptr, len * 4,
190c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                 &receiveLen, sizeof(receiveLen),
191c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                 &subID, sizeof(subID));
192c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    if (!id && receiveLen) {
193257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines        __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG,
194257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines            "message receive buffer too small.  %zu", receiveLen);
195c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
196c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(data, ptr, 0);
197c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return id;
198c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
199c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
200c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
201c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData)
202c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
203c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nContextPeekMessage, con(%p)", con);
204c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL);
205c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    size_t receiveLen;
206c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    uint32_t subID;
207c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen),
208c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                  &subID, sizeof(subID));
209c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    auxDataPtr[0] = (jint)subID;
210c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    auxDataPtr[1] = (jint)receiveLen;
211c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0);
212c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return id;
213c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
214c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
215c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con)
216c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
217c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nContextInitToClient, con(%p)", con);
218c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsContextInitToClient(con);
219c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
220c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
221c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con)
222c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
223c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nContextDeinitToClient, con(%p)", con);
224c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsContextDeinitToClient(con);
225c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
226c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
227c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
228c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnContextSendMessage(JNIEnv *_env, jobject _this, RsContext con, jint id, jintArray data)
229c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
230c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *ptr = NULL;
231c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = 0;
232c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    if (data) {
233c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        len = _env->GetArrayLength(data);
234c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        jint *ptr = _env->GetIntArrayElements(data, NULL);
235c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
236c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", con, id, len);
237c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsContextSendMessage(con, id, (const uint8_t *)ptr, len * sizeof(int));
238c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    if (data) {
239c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
240c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
241c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
242c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
243c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
244c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
245c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
246c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size)
247c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
248c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size);
249c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size);
250c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
251c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
252c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
253c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnElementCreate2(JNIEnv *_env, jobject _this, RsContext con,
254c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                jintArray _ids, jobjectArray _names, jintArray _arraySizes)
255c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
256c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    int fieldCount = _env->GetArrayLength(_ids);
257c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nElementCreate2, con(%p)", con);
258c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
259c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *ids = _env->GetIntArrayElements(_ids, NULL);
260c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL);
261c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
262c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount);
263c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
264c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    const char **nameArray = names.c_str();
265c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    size_t *sizeArray = names.c_str_len();
266c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
267c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint id = (jint)rsElementCreate2(con,
268c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                     (RsElement *)ids, fieldCount,
269c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                     nameArray, fieldCount * sizeof(size_t),  sizeArray,
270c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                     (const uint32_t *)arraySizes, fieldCount);
271c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
272c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT);
273c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT);
274c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return (jint)id;
275c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
276c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
277c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
278c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
279c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
280c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id,
281c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                       jintArray _IDs,
282c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                       jobjectArray _names,
283c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                       jintArray _arraySizes)
284c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
285c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    int dataSize = _env->GetArrayLength(_IDs);
286c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nElementGetSubElements, con(%p)", con);
287c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
288c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
289c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *));
290c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t));
291c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
292c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize);
293c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
294c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    for(jint i = 0; i < dataSize; i++) {
295c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i]));
296c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]);
297c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]);
298c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
299c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
300c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    free(ids);
301c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    free(names);
302c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    free(arraySizes);
303c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
304c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
305c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main// -----------------------------------
306c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
307c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic int
308c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
309c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv)
310c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
311c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)",
312c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            con, eid, dimx, dimy, dimz, mips, faces, yuv);
313c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
314c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv);
315c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return (jint)id;
316c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
317c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
318c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main// -----------------------------------
319c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
320c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
321c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer)
322c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
323c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer);
324c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer);
325c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
326c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
327c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
328c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits)
329c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
330c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits);
331c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits);
332c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
333c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
334c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
335c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc)
336c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
337c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc);
338c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocationGenerateMipmaps(con, (RsAllocation)alloc);
339c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
340c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
341c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic size_t GetBitmapSize(JNIEnv *env, jobject jbitmap) {
342c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AndroidBitmapInfo info;
343c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    memset(&info, 0, sizeof(info));
344c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AndroidBitmap_getInfo(env, jbitmap, &info);
345c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    size_t s = info.width * info.height;
346c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    switch (info.format) {
347c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        case ANDROID_BITMAP_FORMAT_RGBA_8888: s *= 4; break;
348c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        case ANDROID_BITMAP_FORMAT_RGB_565: s *= 2; break;
349c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        case ANDROID_BITMAP_FORMAT_RGBA_4444: s *= 2; break;
350c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
351c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return s;
352c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
353c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
354c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic int
355c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
356c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
357257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    jint id = 0;
358257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    void *pixels = NULL;
359257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    AndroidBitmap_lockPixels(_env, jbitmap, &pixels);
360c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
361257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    if (pixels != NULL) {
362257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines        id = (jint)rsAllocationCreateFromBitmap(con,
363257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines                                                (RsType)type, (RsAllocationMipmapControl)mip,
364257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines                                                pixels, GetBitmapSize(_env, jbitmap), usage);
365257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines        AndroidBitmap_unlockPixels(_env, jbitmap);
366257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    }
367c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return id;
368c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
369c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
370c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic int
371c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
372c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
373257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    jint id = 0;
374257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    void *pixels = NULL;
375257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    AndroidBitmap_lockPixels(_env, jbitmap, &pixels);
376c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
377257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    if (pixels != NULL) {
378257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines        id = (jint)rsAllocationCreateTyped(con,
379257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines                                          (RsType)type, (RsAllocationMipmapControl)mip,
380257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines                                          (uint32_t)usage, (uintptr_t)pixels);
381257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines        AndroidBitmap_unlockPixels(_env, jbitmap);
382257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    }
383c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return id;
384c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
385c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
386c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic int
387c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
388c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
389c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    void *pixels = NULL;
390c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AndroidBitmap_lockPixels(_env, jbitmap, &pixels);
391c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
392c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint id = 0;
393c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    if (pixels != NULL) {
394c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        id = (jint)rsAllocationCubeCreateFromBitmap(con,
395c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                                    (RsType)type, (RsAllocationMipmapControl)mip,
396c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                                    pixels, GetBitmapSize(_env, jbitmap), usage);
397c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        AndroidBitmap_unlockPixels(_env, jbitmap);
398c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
399c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return id;
400c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
401c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
402c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
403c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
404c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
405c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AndroidBitmapInfo info;
406c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    memset(&info, 0, sizeof(info));
407c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AndroidBitmap_getInfo(_env, jbitmap, &info);
408c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
409c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    void *pixels = NULL;
410c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AndroidBitmap_lockPixels(_env, jbitmap, &pixels);
411c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
412c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    if (pixels != NULL) {
413c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        rsAllocation2DData(con, (RsAllocation)alloc, 0, 0,
414c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                           0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
415c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                           info.width, info.height, pixels, GetBitmapSize(_env, jbitmap), 0);
416c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        AndroidBitmap_unlockPixels(_env, jbitmap);
417c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
418c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
419c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
420c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
421c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
422c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
423c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AndroidBitmapInfo info;
424c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    memset(&info, 0, sizeof(info));
425c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AndroidBitmap_getInfo(_env, jbitmap, &info);
426c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
427c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    void *pixels = NULL;
428c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AndroidBitmap_lockPixels(_env, jbitmap, &pixels);
429c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
430c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    if (pixels != NULL) {
431c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        rsAllocationCopyToBitmap(con, (RsAllocation)alloc, pixels, GetBitmapSize(_env, jbitmap));
432c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        AndroidBitmap_unlockPixels(_env, jbitmap);
433c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
434c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    //bitmap.notifyPixelsChanged();
435c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
436c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
437c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
438c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
439c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData1D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jintArray data, int sizeBytes)
440c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
441c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
442c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocation1DData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
443c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *ptr = _env->GetIntArrayElements(data, NULL);
444c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
445c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
446c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
447c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
448c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
449c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData1D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jshortArray data, int sizeBytes)
450c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
451c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
452c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocation1DData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
453c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jshort *ptr = _env->GetShortArrayElements(data, NULL);
454c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
455c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
456c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
457c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
458c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
459c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData1D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jbyteArray data, int sizeBytes)
460c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
461c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
462c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocation1DData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
463c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
464c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
465c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
466c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
467c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
468c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
469c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData1D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jfloatArray data, int sizeBytes)
470c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
471c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
472c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocation1DData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes);
473c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
474c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes);
475c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
476c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
477c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
478c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
479c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main//    native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes);
480c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationElementData1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint compIdx, jbyteArray data, int sizeBytes)
481c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
482c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
483c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes);
484c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
485c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx);
486c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
487c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
488c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
489c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
490c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
491c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                    jint w, jint h, jshortArray data, int sizeBytes)
492c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
493c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
494c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocation2DData_s, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
495c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jshort *ptr = _env->GetShortArrayElements(data, NULL);
496c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
497c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
498c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
499c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
500c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
501c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
502c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                    jint w, jint h, jbyteArray data, int sizeBytes)
503c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
504c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
505c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocation2DData_b, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
506c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
507c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
508c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
509c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
510c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
511c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
512c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
513c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                    jint w, jint h, jintArray data, int sizeBytes)
514c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
515c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
516c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
517c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *ptr = _env->GetIntArrayElements(data, NULL);
518c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
519c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
520c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
521c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
522c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
523c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face,
524c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                    jint w, jint h, jfloatArray data, int sizeBytes)
525c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
526c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
527c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocation2DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len);
528c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
529c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes, 0);
530c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
531c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
532c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
533c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
534c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con,
535c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                        jint dstAlloc, jint dstXoff, jint dstYoff,
536c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                        jint dstMip, jint dstFace,
537c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                        jint width, jint height,
538c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                        jint srcAlloc, jint srcXoff, jint srcYoff,
539c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                        jint srcMip, jint srcFace)
540c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
541c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
542c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            " dstMip(%i), dstFace(%i), width(%i), height(%i),"
543c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)",
544c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
545c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
546c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
547c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocationCopy2DRange(con,
548c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                            (RsAllocation)dstAlloc,
549c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                            dstXoff, dstYoff,
550c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                            dstMip, dstFace,
551c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                            width, height,
552c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                            (RsAllocation)srcAlloc,
553c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                            srcXoff, srcYoff,
554c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                            srcMip, srcFace);
555c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
556c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
557c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
558c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData3D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod,
559c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                    jint w, jint h, jint d, jshortArray data, int sizeBytes)
560c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
561c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
562c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocation3DData_s, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len);
563c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jshort *ptr = _env->GetShortArrayElements(data, NULL);
564c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
565c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT);
566c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
567c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
568c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
569c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData3D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod,
570c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                    jint w, jint h, jint d, jbyteArray data, int sizeBytes)
571c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
572c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
573c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocation3DData_b, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len);
574c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
575c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
576c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
577c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
578c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
579c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
580c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData3D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod,
581c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                    jint w, jint h, jint d, jintArray data, int sizeBytes)
582c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
583c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
584c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocation3DData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len);
585c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *ptr = _env->GetIntArrayElements(data, NULL);
586c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
587c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT);
588c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
589c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
590c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
591c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData3D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint zoff, jint lod,
592c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                    jint w, jint h, jint d, jfloatArray data, int sizeBytes)
593c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
594c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
595c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocation3DData_f, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, zoff, w, h, d, len);
596c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
597c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocation3DData(con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
598c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT);
599c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
600c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
601c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
602c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationData3D_alloc(JNIEnv *_env, jobject _this, RsContext con,
603c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                        jint dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
604c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                        jint dstMip,
605c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                        jint width, jint height, jint depth,
606c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                        jint srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff,
607c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                        jint srcMip)
608c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
609c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i),"
610c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            " dstMip(%i), width(%i), height(%i),"
611c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)",
612c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace,
613c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main            width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace);
614c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
615c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocationCopy3DRange(con,
616c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                            (RsAllocation)dstAlloc,
617c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                            dstXoff, dstYoff, dstZoff, dstMip,
618c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                            width, height, depth,
619c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                            (RsAllocation)srcAlloc,
620c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                            srcXoff, srcYoff, srcZoff, srcMip);
621c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
622c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
623c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
624c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data)
625c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
626c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
627c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
628c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *ptr = _env->GetIntArrayElements(data, NULL);
629c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jsize length = _env->GetArrayLength(data);
630c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(int));
631c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(data, ptr, 0);
632c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
633c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
634c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
635c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data)
636c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
637c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
638c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
639c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jshort *ptr = _env->GetShortArrayElements(data, NULL);
640c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jsize length = _env->GetArrayLength(data);
641c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(short));
642c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseShortArrayElements(data, ptr, 0);
643c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
644c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
645c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
646c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data)
647c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
648c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
649c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
650c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
651c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jsize length = _env->GetArrayLength(data);
652c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(char));
653c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseByteArrayElements(data, ptr, 0);
654c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
655c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
656c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
657c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data)
658c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
659c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
660c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len);
661c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jfloat *ptr = _env->GetFloatArrayElements(data, NULL);
662c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jsize length = _env->GetArrayLength(data);
663c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(float));
664c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseFloatArrayElements(data, ptr, 0);
665c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
666c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
667c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
668c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a)
669c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
670c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a);
671c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return (jint) rsaAllocationGetType(con, (RsAllocation)a);
672c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
673c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
674c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
675c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX)
676c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
677c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX);
678c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsAllocationResize1D(con, (RsAllocation)alloc, dimX);
679c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
680c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
681c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main// -----------------------------------
682c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
683c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
684c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot)
685c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
686c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot);
687c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot);
688c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
689c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
690c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
691c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
692c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
693c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
694c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptSetVarI(con, (RsScript)script, slot, val);
695c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
696c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
697c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
698c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val)
699c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
700c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val);
701c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val);
702c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
703c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
704c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
705c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val)
706c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
707c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val);
708c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptSetVarJ(con, (RsScript)script, slot, val);
709c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
710c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
711c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
712c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val)
713c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
714c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val);
715c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptSetVarF(con, (RsScript)script, slot, val);
716c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
717c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
718c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
719c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val)
720c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
721c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val);
722c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptSetVarD(con, (RsScript)script, slot, val);
723c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
724c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
725c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
726c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
727c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
728c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
729c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
730c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
731c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptSetVarV(con, (RsScript)script, slot, ptr, len);
732c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
733c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
734c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
735c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
736c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims)
737c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
738c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
739c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
740c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
741c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint dimsLen = _env->GetArrayLength(dims) * sizeof(int);
742c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *dimsPtr = _env->GetIntArrayElements(dims, NULL);
743c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptSetVarVE(con, (RsScript)script, slot, ptr, len, (RsElement)elem,
744c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                     (const size_t*) dimsPtr, dimsLen);
745c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
746c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT);
747c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
748c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
749c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
750c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
751c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone)
752c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
753c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone);
754c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
755c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint length = _env->GetArrayLength(timeZone);
756c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jbyte* timeZone_ptr;
757c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0);
758c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
759c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length);
760c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
761c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    if (timeZone_ptr) {
762c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0);
763c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
764c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
765c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
766c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
767c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot)
768c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
769c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj);
770c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptInvoke(con, (RsScript)obj, slot);
771c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
772c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
773c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
774c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data)
775c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
776c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
777c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(data);
778c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jbyte *ptr = _env->GetByteArrayElements(data, NULL);
779c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptInvokeV(con, (RsScript)script, slot, ptr, len);
780c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
781c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
782c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
783c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
784c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptForEach(JNIEnv *_env, jobject _this, RsContext con,
785c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main               jint script, jint slot, jint ain, jint aout)
786c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
787c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
788c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, NULL, 0);
789c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
790c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
791c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptForEachV(JNIEnv *_env, jobject _this, RsContext con,
792c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                jint script, jint slot, jint ain, jint aout, jbyteArray params)
793c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
794c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
795c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(params);
796c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jbyte *ptr = _env->GetByteArrayElements(params, NULL);
797c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, NULL, 0);
798c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
799c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
800c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
801c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
802c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptForEachClipped(JNIEnv *_env, jobject _this, RsContext con,
803c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                      jint script, jint slot, jint ain, jint aout,
804c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                      jint xstart, jint xend,
805c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                      jint ystart, jint yend, jint zstart, jint zend)
806c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
807c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
808c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    RsScriptCall sc;
809c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.xStart = xstart;
810c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.xEnd = xend;
811c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.yStart = ystart;
812c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.yEnd = yend;
813c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.zStart = zstart;
814c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.zEnd = zend;
815c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
816c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.arrayStart = 0;
817c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.arrayEnd = 0;
818c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc));
819c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
820c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
821c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
822c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptForEachClippedV(JNIEnv *_env, jobject _this, RsContext con,
823c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                       jint script, jint slot, jint ain, jint aout,
824c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                       jbyteArray params, jint xstart, jint xend,
825c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                       jint ystart, jint yend, jint zstart, jint zend)
826c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
827c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", con, (void *)script, slot);
828c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint len = _env->GetArrayLength(params);
829c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jbyte *ptr = _env->GetByteArrayElements(params, NULL);
830c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    RsScriptCall sc;
831c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.xStart = xstart;
832c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.xEnd = xend;
833c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.yStart = ystart;
834c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.yEnd = yend;
835c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.zStart = zstart;
836c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.zEnd = zend;
837c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE;
838c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.arrayStart = 0;
839c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    sc.arrayEnd = 0;
840c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, &sc, sizeof(sc));
841c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT);
842c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
843c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
844c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main// -----------------------------------
845c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
846c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
847c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptCCreate(JNIEnv *_env, jobject _this, RsContext con,
848c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main               jstring resName, jstring cacheDir,
849c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main               jbyteArray scriptRef, jint length)
850c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
851c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptCCreate, con(%p)", con);
852c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
853c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AutoJavaStringToUTF8 resNameUTF(_env, resName);
854c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir);
855c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint ret = 0;
856c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jbyte* script_ptr = NULL;
857c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint _exception = 0;
858c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint remaining;
859c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    if (!scriptRef) {
860c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        _exception = 1;
861c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null");
862c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        goto exit;
863c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
864c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    if (length < 0) {
865c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        _exception = 1;
866c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0");
867c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        goto exit;
868c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
869c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    remaining = _env->GetArrayLength(scriptRef);
870c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    if (remaining < length) {
871c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        _exception = 1;
872c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        //jniThrowException(_env, "java/lang/IllegalArgumentException",
873c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        //        "length > script.length - offset");
874c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        goto exit;
875c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
876c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    script_ptr = (jbyte *)
877c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0);
878c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
879c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    //rsScriptCSetText(con, (const char *)script_ptr, length);
880c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
881c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    ret = (jint)rsScriptCCreate(con,
882c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                resNameUTF.c_str(), resNameUTF.length(),
883c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                cacheDirUTF.c_str(), cacheDirUTF.length(),
884c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                (const char *)script_ptr, length);
885c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
886c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainexit:
887c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    if (script_ptr) {
888c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr,
889c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                _exception ? JNI_ABORT: 0);
890c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
891c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
892c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return ret;
893c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
894c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
895c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
896c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptIntrinsicCreate(JNIEnv *_env, jobject _this, RsContext con, jint id, jint eid)
897c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
898c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", con, id, (void *)eid);
899c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return (jint)rsScriptIntrinsicCreate(con, id, (RsElement)eid);
900c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
901c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
902c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
903c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptKernelIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot, jint sig)
904c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
905c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", con, (void *)sid, slot, sig);
906c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return (jint)rsScriptKernelIDCreate(con, (RsScript)sid, slot, sig);
907c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
908c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
909c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
910c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptFieldIDCreate(JNIEnv *_env, jobject _this, RsContext con, jint sid, jint slot)
911c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
912c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", con, (void *)sid, slot);
913c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return (jint)rsScriptFieldIDCreate(con, (RsScript)sid, slot);
914c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
915c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
916c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
917c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptGroupCreate(JNIEnv *_env, jobject _this, RsContext con, jintArray _kernels, jintArray _src,
918c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jintArray _dstk, jintArray _dstf, jintArray _types)
919c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
920c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptGroupCreate, con(%p)", con);
921c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
922c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint kernelsLen = _env->GetArrayLength(_kernels) * sizeof(int);
923c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *kernelsPtr = _env->GetIntArrayElements(_kernels, NULL);
924c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint srcLen = _env->GetArrayLength(_src) * sizeof(int);
925c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *srcPtr = _env->GetIntArrayElements(_src, NULL);
926c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint dstkLen = _env->GetArrayLength(_dstk) * sizeof(int);
927c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *dstkPtr = _env->GetIntArrayElements(_dstk, NULL);
928c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint dstfLen = _env->GetArrayLength(_dstf) * sizeof(int);
929c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *dstfPtr = _env->GetIntArrayElements(_dstf, NULL);
930c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint typesLen = _env->GetArrayLength(_types) * sizeof(int);
931c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint *typesPtr = _env->GetIntArrayElements(_types, NULL);
932c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
933c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    int id = (int)rsScriptGroupCreate(con,
934c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                               (RsScriptKernelID *)kernelsPtr, kernelsLen,
935c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                               (RsScriptKernelID *)srcPtr, srcLen,
936c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                               (RsScriptKernelID *)dstkPtr, dstkLen,
937c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                               (RsScriptFieldID *)dstfPtr, dstfLen,
938c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                               (RsType *)typesPtr, typesLen);
939c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
940c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(_kernels, kernelsPtr, 0);
941c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(_src, srcPtr, 0);
942c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(_dstk, dstkPtr, 0);
943c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(_dstf, dstfPtr, 0);
944c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    _env->ReleaseIntArrayElements(_types, typesPtr, 0);
945c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return id;
946c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
947c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
948c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
949c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptGroupSetInput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
950c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
951c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
952c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        (void *)gid, (void *)kid, (void *)alloc);
953c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptGroupSetInput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
954c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
955c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
956c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
957c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptGroupSetOutput(JNIEnv *_env, jobject _this, RsContext con, jint gid, jint kid, jint alloc)
958c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
959c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", con,
960c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        (void *)gid, (void *)kid, (void *)alloc);
961c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptGroupSetOutput(con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc);
962c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
963c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
964c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic void
965c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnScriptGroupExecute(JNIEnv *_env, jobject _this, RsContext con, jint gid)
966c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
967c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", con, (void *)gid);
968c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    rsScriptGroupExecute(con, (RsScriptGroup)gid);
969c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
970c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
971c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main// ---------------------------------------------------------------------------
972c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
973c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic jint
974c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott MainnSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter,
975c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main               jint wrapS, jint wrapT, jint wrapR, jfloat aniso)
976c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
977c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    LOG_API("nSamplerCreate, con(%p)", con);
978c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return (jint)rsSamplerCreate(con,
979c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                 (RsSamplerValue)magFilter,
980c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                 (RsSamplerValue)minFilter,
981c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                 (RsSamplerValue)wrapS,
982c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                 (RsSamplerValue)wrapT,
983c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                 (RsSamplerValue)wrapR,
984c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main                                 aniso);
985c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
986c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
987c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main// ---------------------------------------------------------------------------
988c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
989c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
990c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic const char *classPathName = "android/support/v8/renderscript/RenderScript";
991c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
992c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainstatic JNINativeMethod methods[] = {
993c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"nDeviceCreate",                  "()I",                                     (void*)nDeviceCreate },
994c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"nDeviceDestroy",                 "(I)V",                                    (void*)nDeviceDestroy },
995c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"nDeviceSetConfig",               "(III)V",                                  (void*)nDeviceSetConfig },
996c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"nContextGetUserMessage",         "(I[I)I",                                  (void*)nContextGetUserMessage },
997c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"nContextGetErrorMessage",        "(I)Ljava/lang/String;",                   (void*)nContextGetErrorMessage },
998c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"nContextPeekMessage",            "(I[I)I",                                  (void*)nContextPeekMessage },
999c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1000c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"nContextInitToClient",           "(I)V",                                    (void*)nContextInitToClient },
1001c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"nContextDeinitToClient",         "(I)V",                                    (void*)nContextDeinitToClient },
1002c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1003c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1004c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main// All methods below are thread protected in java.
1005c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnContextCreate",                 "(IIII)I",                               (void*)nContextCreate },
1006c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnContextFinish",                 "(I)V",                                  (void*)nContextFinish },
1007c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnContextSetPriority",            "(II)V",                                 (void*)nContextSetPriority },
1008c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnContextDestroy",                "(I)V",                                  (void*)nContextDestroy },
1009c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnContextDump",                   "(II)V",                                 (void*)nContextDump },
1010c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnContextSendMessage",            "(II[I)V",                               (void*)nContextSendMessage },
1011c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnObjDestroy",                    "(II)V",                                 (void*)nObjDestroy },
1012c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1013c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnElementCreate",                 "(IIIZI)I",                              (void*)nElementCreate },
1014c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnElementCreate2",                "(I[I[Ljava/lang/String;[I)I",           (void*)nElementCreate2 },
1015c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnElementGetSubElements",         "(II[I[Ljava/lang/String;[I)V",          (void*)nElementGetSubElements },
1016c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1017c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnTypeCreate",                    "(IIIIIZZI)I",                           (void*)nTypeCreate },
1018c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1019c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationCreateTyped",         "(IIIII)I",                               (void*)nAllocationCreateTyped },
1020c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationCreateFromBitmap",    "(IIILandroid/graphics/Bitmap;I)I",      (void*)nAllocationCreateFromBitmap },
1021c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationCreateBitmapBackedAllocation",    "(IIILandroid/graphics/Bitmap;I)I",      (void*)nAllocationCreateBitmapBackedAllocation },
1022c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I",      (void*)nAllocationCubeCreateFromBitmap },
1023c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1024c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationCopyFromBitmap",      "(IILandroid/graphics/Bitmap;)V",        (void*)nAllocationCopyFromBitmap },
1025c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationCopyToBitmap",        "(IILandroid/graphics/Bitmap;)V",        (void*)nAllocationCopyToBitmap },
1026c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1027c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationSyncAll",             "(III)V",                                (void*)nAllocationSyncAll },
1028c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData1D",              "(IIIII[II)V",                           (void*)nAllocationData1D_i },
1029c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData1D",              "(IIIII[SI)V",                           (void*)nAllocationData1D_s },
1030c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData1D",              "(IIIII[BI)V",                           (void*)nAllocationData1D_b },
1031c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData1D",              "(IIIII[FI)V",                           (void*)nAllocationData1D_f },
1032c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationElementData1D",       "(IIIII[BI)V",                           (void*)nAllocationElementData1D },
1033c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData2D",              "(IIIIIIII[II)V",                        (void*)nAllocationData2D_i },
1034c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData2D",              "(IIIIIIII[SI)V",                        (void*)nAllocationData2D_s },
1035c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData2D",              "(IIIIIIII[BI)V",                        (void*)nAllocationData2D_b },
1036c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData2D",              "(IIIIIIII[FI)V",                        (void*)nAllocationData2D_f },
1037c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData2D",              "(IIIIIIIIIIIII)V",                      (void*)nAllocationData2D_alloc },
1038c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData3D",              "(IIIIIIIII[II)V",                       (void*)nAllocationData3D_i },
1039c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData3D",              "(IIIIIIIII[SI)V",                       (void*)nAllocationData3D_s },
1040c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData3D",              "(IIIIIIIII[BI)V",                       (void*)nAllocationData3D_b },
1041c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData3D",              "(IIIIIIIII[FI)V",                       (void*)nAllocationData3D_f },
1042c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationData3D",              "(IIIIIIIIIIIIII)V",                     (void*)nAllocationData3D_alloc },
1043c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationRead",                "(II[I)V",                               (void*)nAllocationRead_i },
1044c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationRead",                "(II[S)V",                               (void*)nAllocationRead_s },
1045c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationRead",                "(II[B)V",                               (void*)nAllocationRead_b },
1046c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationRead",                "(II[F)V",                               (void*)nAllocationRead_f },
1047c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationGetType",             "(II)I",                                 (void*)nAllocationGetType},
1048c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationResize1D",            "(III)V",                                (void*)nAllocationResize1D },
1049c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnAllocationGenerateMipmaps",     "(II)V",                                 (void*)nAllocationGenerateMipmaps },
1050c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1051c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptBindAllocation",          "(IIII)V",                               (void*)nScriptBindAllocation },
1052c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptSetTimeZone",             "(II[B)V",                               (void*)nScriptSetTimeZone },
1053c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptInvoke",                  "(III)V",                                (void*)nScriptInvoke },
1054c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptInvokeV",                 "(III[B)V",                              (void*)nScriptInvokeV },
1055c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptForEach",                 "(IIIII)V",                              (void*)nScriptForEach },
1056c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptForEach",                 "(IIIII[B)V",                            (void*)nScriptForEachV },
1057c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptForEachClipped",          "(IIIIIIIIIII)V",                        (void*)nScriptForEachClipped },
1058c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptForEachClipped",          "(IIIII[BIIIIII)V",                      (void*)nScriptForEachClippedV },
1059c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptSetVarI",                 "(IIII)V",                               (void*)nScriptSetVarI },
1060c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptSetVarJ",                 "(IIIJ)V",                               (void*)nScriptSetVarJ },
1061c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptSetVarF",                 "(IIIF)V",                               (void*)nScriptSetVarF },
1062c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptSetVarD",                 "(IIID)V",                               (void*)nScriptSetVarD },
1063c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptSetVarV",                 "(III[B)V",                              (void*)nScriptSetVarV },
1064c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptSetVarVE",                "(III[BI[I)V",                           (void*)nScriptSetVarVE },
1065c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptSetVarObj",               "(IIII)V",                               (void*)nScriptSetVarObj },
1066c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1067c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptCCreate",                 "(ILjava/lang/String;Ljava/lang/String;[BI)I",  (void*)nScriptCCreate },
1068c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptIntrinsicCreate",         "(III)I",                                (void*)nScriptIntrinsicCreate },
1069c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptKernelIDCreate",          "(IIII)I",                               (void*)nScriptKernelIDCreate },
1070c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptFieldIDCreate",           "(III)I",                                (void*)nScriptFieldIDCreate },
1071c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptGroupCreate",             "(I[I[I[I[I[I)I",                        (void*)nScriptGroupCreate },
1072c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptGroupSetInput",           "(IIII)V",                               (void*)nScriptGroupSetInput },
1073c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptGroupSetOutput",          "(IIII)V",                               (void*)nScriptGroupSetOutput },
1074c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnScriptGroupExecute",            "(II)V",                                 (void*)nScriptGroupExecute },
1075c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1076c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{"rsnSamplerCreate",                 "(IIIIIIF)I",                            (void*)nSamplerCreate },
1077c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1078c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main};
1079c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1080c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main// ---------------------------------------------------------------------------
1081c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1082c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainjint JNI_OnLoad(JavaVM* vm, void* reserved)
1083c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main{
1084c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    JNIEnv* env = NULL;
1085257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    jclass clazz = NULL;
1086c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    jint result = -1;
1087c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1088c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
1089257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines        __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
1090257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines            "ERROR: GetEnv failed\n");
1091257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines        goto bail;
1092257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    }
1093257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    if (env == NULL) {
1094257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines        __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "ERROR: env == NULL");
1095257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines        goto bail;
1096257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    }
1097257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines
1098257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    clazz = env->FindClass(classPathName);
1099257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    if (clazz == NULL) {
1100c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        goto bail;
1101c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
1102c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1103257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines    if (env->RegisterNatives(clazz, methods, NELEM(methods)) < 0) {
1104257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines        __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,
1105257cecb5e24c9af71ba4d621887e88e46b0ac411Stephen Hines            "ERROR: MediaPlayer native registration failed\n");
1106c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main        goto bail;
1107c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    }
1108c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1109c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    /* success -- return valid version number */
1110c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    result = JNI_VERSION_1_4;
1111c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main
1112c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Mainbail:
1113c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main    return result;
1114c89ad4606ae29e103b85bdfc40c57e36c8877dbaScott Main}
1115