android_renderscript_RenderScript.cpp revision 98a281354fe06d1f970d0521c9a08d9eb0aa1a45
198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams/* 298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * Copyright (C) 2011-2012 The Android Open Source Project 398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * Licensed under the Apache License, Version 2.0 (the "License"); 598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * you may not use this file except in compliance with the License. 698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * You may obtain a copy of the License at 798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * http://www.apache.org/licenses/LICENSE-2.0 998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * 1098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * Unless required by applicable law or agreed to in writing, software 1198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * distributed under the License is distributed on an "AS IS" BASIS, 1298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * See the License for the specific language governing permissions and 1498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams * limitations under the License. 1598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams */ 1698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 1798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#define LOG_TAG "libRS_jni" 1898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 1998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <stdlib.h> 2098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <stdio.h> 2198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <fcntl.h> 2298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <unistd.h> 2398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <math.h> 2498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <utils/misc.h> 2598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 2698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <core/SkBitmap.h> 2798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <core/SkPixelRef.h> 2898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <core/SkStream.h> 2998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <core/SkTemplates.h> 3098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <images/SkImageDecoder.h> 3198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 3298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <androidfw/Asset.h> 3398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <androidfw/AssetManager.h> 3498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <androidfw/ResourceTypes.h> 3598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 3698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include "jni.h" 3798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include "JNIHelp.h" 3898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include "android_runtime/AndroidRuntime.h" 3998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include "android_runtime/android_view_Surface.h" 4098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include "android_runtime/android_util_AssetManager.h" 4198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 4298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <rs.h> 4398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <rsEnv.h> 4498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <gui/Surface.h> 4598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <gui/SurfaceTexture.h> 4698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <gui/SurfaceTextureClient.h> 4798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#include <android_runtime/android_graphics_SurfaceTexture.h> 4898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 4998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams//#define LOG_API ALOG 5098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams#define LOG_API(...) 5198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 5298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsusing namespace android; 5398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 5498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsclass AutoJavaStringToUTF8 { 5598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samspublic: 5698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) { 5798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams fCStr = env->GetStringUTFChars(str, NULL); 5898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams fLength = env->GetStringUTFLength(str); 5998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 6098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams ~AutoJavaStringToUTF8() { 6198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams fEnv->ReleaseStringUTFChars(fJStr, fCStr); 6298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 6398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams const char* c_str() const { return fCStr; } 6498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jsize length() const { return fLength; } 6598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 6698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsprivate: 6798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams JNIEnv* fEnv; 6898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jstring fJStr; 6998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams const char* fCStr; 7098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jsize fLength; 7198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams}; 7298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 7398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsclass AutoJavaStringArrayToUTF8 { 7498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samspublic: 7598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength) 7698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams : mEnv(env), mStrings(strings), mStringsLength(stringsLength) { 7798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mCStrings = NULL; 7898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mSizeArray = NULL; 7998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if (stringsLength > 0) { 8098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mCStrings = (const char **)calloc(stringsLength, sizeof(char *)); 8198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t)); 8298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams for (jsize ct = 0; ct < stringsLength; ct ++) { 8398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); 8498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL); 8598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mSizeArray[ct] = mEnv->GetStringUTFLength(s); 8698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 8798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 8898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 8998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams ~AutoJavaStringArrayToUTF8() { 9098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams for (jsize ct=0; ct < mStringsLength; ct++) { 9198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); 9298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams mEnv->ReleaseStringUTFChars(s, mCStrings[ct]); 9398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 9498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams free(mCStrings); 9598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams free(mSizeArray); 9698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 9798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams const char **c_str() const { return mCStrings; } 9898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams size_t *c_str_len() const { return mSizeArray; } 9998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jsize length() const { return mStringsLength; } 10098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 10198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsprivate: 10298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams JNIEnv *mEnv; 10398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jobjectArray mStrings; 10498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams const char **mCStrings; 10598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams size_t *mSizeArray; 10698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jsize mStringsLength; 10798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams}; 10898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 10998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// --------------------------------------------------------------------------- 11098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 11198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jfieldID gContextId = 0; 11298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jfieldID gNativeBitmapID = 0; 11398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jfieldID gTypeNativeCache = 0; 11498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 11598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void _nInit(JNIEnv *_env, jclass _this) 11698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 11798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams gContextId = _env->GetFieldID(_this, "mContext", "I"); 11898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 11998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jclass bitmapClass = _env->FindClass("android/graphics/Bitmap"); 12098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I"); 12198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 12298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 12398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// --------------------------------------------------------------------------- 12498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 12598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 12698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnContextFinish(JNIEnv *_env, jobject _this, RsContext con) 12798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 12898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nContextFinish, con(%p)", con); 12998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsContextFinish(con); 13098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 13198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 13298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 13398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnObjDestroy(JNIEnv *_env, jobject _this, RsContext con, jint obj) 13498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 13598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nObjDestroy, con(%p) obj(%p)", con, (void *)obj); 13698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsObjDestroy(con, (void *)obj); 13798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 13898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 13998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// --------------------------------------------------------------------------- 14098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 14198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jint 14298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnDeviceCreate(JNIEnv *_env, jobject _this) 14398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 14498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nDeviceCreate"); 14598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return (jint)rsDeviceCreate(); 14698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 14798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 14898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 14998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnDeviceDestroy(JNIEnv *_env, jobject _this, jint dev) 15098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 15198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nDeviceDestroy"); 15298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return rsDeviceDestroy((RsDevice)dev); 15398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 15498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 15598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 15698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnDeviceSetConfig(JNIEnv *_env, jobject _this, jint dev, jint p, jint value) 15798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 15898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); 15998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); 16098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 16198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 16298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jint 16398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnContextCreate(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer) 16498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 16598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nContextCreate"); 16698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return (jint)rsContextCreate((RsDevice)dev, ver, sdkVer); 16798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 16898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 16998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jint 17098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnContextCreateGL(JNIEnv *_env, jobject _this, jint dev, jint ver, jint sdkVer, 17198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int colorMin, int colorPref, 17298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int alphaMin, int alphaPref, 17398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int depthMin, int depthPref, 17498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int stencilMin, int stencilPref, 17598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int samplesMin, int samplesPref, float samplesQ, 17698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int dpi) 17798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 17898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams RsSurfaceConfig sc; 17998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sc.alphaMin = alphaMin; 18098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sc.alphaPref = alphaPref; 18198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sc.colorMin = colorMin; 18298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sc.colorPref = colorPref; 18398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sc.depthMin = depthMin; 18498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sc.depthPref = depthPref; 18598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sc.samplesMin = samplesMin; 18698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sc.samplesPref = samplesPref; 18798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams sc.samplesQ = samplesQ; 18898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 18998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nContextCreateGL"); 19098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return (jint)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi); 19198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 19298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 19398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 19498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnContextSetPriority(JNIEnv *_env, jobject _this, RsContext con, jint p) 19598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 19698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("ContextSetPriority, con(%p), priority(%i)", con, p); 19798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsContextSetPriority(con, p); 19898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 19998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 20098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 20198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 20298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 20398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnContextDestroy(JNIEnv *_env, jobject _this, RsContext con) 20498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 20598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nContextDestroy, con(%p)", con); 20698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsContextDestroy(con); 20798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 20898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 20998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 21098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnContextDump(JNIEnv *_env, jobject _this, RsContext con, jint bits) 21198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 21298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); 21398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsContextDump((RsContext)con, bits); 21498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 21598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 21698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 21798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jstring 21898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnContextGetErrorMessage(JNIEnv *_env, jobject _this, RsContext con) 21998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 22098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nContextGetErrorMessage, con(%p)", con); 22198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams char buf[1024]; 22298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 22398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams size_t receiveLen; 22498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams uint32_t subID; 22598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int id = rsContextGetMessage(con, 22698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams buf, sizeof(buf), 22798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams &receiveLen, sizeof(receiveLen), 22898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams &subID, sizeof(subID)); 22998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if (!id && receiveLen) { 23098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams ALOGV("message receive buffer too small. %i", receiveLen); 23198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 23298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return _env->NewStringUTF(buf); 23398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 23498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 23598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jint 23698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnContextGetUserMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray data) 23798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 23898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 23998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nContextGetMessage, con(%p), len(%i)", con, len); 24098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint *ptr = _env->GetIntArrayElements(data, NULL); 24198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams size_t receiveLen; 24298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams uint32_t subID; 24398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int id = rsContextGetMessage(con, 24498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams ptr, len * 4, 24598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams &receiveLen, sizeof(receiveLen), 24698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams &subID, sizeof(subID)); 24798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if (!id && receiveLen) { 24898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams ALOGV("message receive buffer too small. %i", receiveLen); 24998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 25098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseIntArrayElements(data, ptr, 0); 25198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return id; 25298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 25398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 25498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jint 25598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnContextPeekMessage(JNIEnv *_env, jobject _this, RsContext con, jintArray auxData) 25698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 25798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nContextPeekMessage, con(%p)", con); 25898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL); 25998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams size_t receiveLen; 26098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams uint32_t subID; 26198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int id = rsContextPeekMessage(con, &receiveLen, sizeof(receiveLen), 26298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams &subID, sizeof(subID)); 26398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams auxDataPtr[0] = (jint)subID; 26498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams auxDataPtr[1] = (jint)receiveLen; 26598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseIntArrayElements(auxData, auxDataPtr, 0); 26698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return id; 26798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 26898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 26998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void nContextInitToClient(JNIEnv *_env, jobject _this, RsContext con) 27098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 27198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nContextInitToClient, con(%p)", con); 27298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsContextInitToClient(con); 27398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 27498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 27598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void nContextDeinitToClient(JNIEnv *_env, jobject _this, RsContext con) 27698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 27798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nContextDeinitToClient, con(%p)", con); 27898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsContextDeinitToClient(con); 27998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 28098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 28198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 28298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jint 28398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, jboolean norm, jint size) 28498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 28598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", con, type, kind, norm, size); 28698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return (jint)rsElementCreate(con, (RsDataType)type, (RsDataKind)kind, norm, size); 28798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 28898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 28998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jint 29098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnElementCreate2(JNIEnv *_env, jobject _this, RsContext con, 29198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jintArray _ids, jobjectArray _names, jintArray _arraySizes) 29298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 29398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int fieldCount = _env->GetArrayLength(_ids); 29498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nElementCreate2, con(%p)", con); 29598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 29698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint *ids = _env->GetIntArrayElements(_ids, NULL); 29798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL); 29898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 29998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount); 30098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 30198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams const char **nameArray = names.c_str(); 30298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams size_t *sizeArray = names.c_str_len(); 30398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 30498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint id = (jint)rsElementCreate2(con, 30598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (RsElement *)ids, fieldCount, 30698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams nameArray, fieldCount * sizeof(size_t), sizeArray, 30798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (const uint32_t *)arraySizes, fieldCount); 30898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 30998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT); 31098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT); 31198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return (jint)id; 31298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 31398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 31498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 31598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 31698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 31798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnElementGetSubElements(JNIEnv *_env, jobject _this, RsContext con, jint id, 31898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jintArray _IDs, 31998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jobjectArray _names, 32098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jintArray _arraySizes) 32198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 32298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int dataSize = _env->GetArrayLength(_IDs); 32398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nElementGetSubElements, con(%p)", con); 32498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 32598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams uint32_t *ids = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t)); 32698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams const char **names = (const char **)malloc((uint32_t)dataSize * sizeof(const char *)); 32798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams uint32_t *arraySizes = (uint32_t *)malloc((uint32_t)dataSize * sizeof(uint32_t)); 32898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 32998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsaElementGetSubElements(con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize); 33098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 33198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams for(jint i = 0; i < dataSize; i++) { 33298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->SetObjectArrayElement(_names, i, _env->NewStringUTF(names[i])); 33398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->SetIntArrayRegion(_IDs, i, 1, (const jint*)&ids[i]); 33498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->SetIntArrayRegion(_arraySizes, i, 1, (const jint*)&arraySizes[i]); 33598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 33698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 33798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams free(ids); 33898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams free(names); 33998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams free(arraySizes); 34098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 34198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 34298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// ----------------------------------- 34398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 34498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic int 34598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid, 34698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces) 34798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 34898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)", 34998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams con, eid, dimx, dimy, dimz, mips, faces); 35098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 35198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint id = (jint)rsTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces); 35298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return (jint)id; 35398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 35498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 35598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// ----------------------------------- 35698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 35798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jint 35898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationCreateTyped(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mips, jint usage, jint pointer) 35998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 36098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", con, (RsElement)type, mips, usage, (void *)pointer); 36198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return (jint) rsAllocationCreateTyped(con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uint32_t)pointer); 36298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 36398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 36498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 36598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits) 36698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 36798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", con, (RsAllocation)a, bits); 36898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits); 36998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 37098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 37198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 37298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc) 37398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 37498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc); 37598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocationGenerateMipmaps(con, (RsAllocation)alloc); 37698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 37798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 37898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic int 37998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) 38098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 38198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams SkBitmap const * nativeBitmap = 38298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 38398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams const SkBitmap& bitmap(*nativeBitmap); 38498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 38598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams bitmap.lockPixels(); 38698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams const void* ptr = bitmap.getPixels(); 38798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint id = (jint)rsAllocationCreateFromBitmap(con, 38898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (RsType)type, (RsAllocationMipmapControl)mip, 38998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams ptr, bitmap.getSize(), usage); 39098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams bitmap.unlockPixels(); 39198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return id; 39298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 39398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 39498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic int 39598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage) 39698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 39798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams SkBitmap const * nativeBitmap = 39898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 39998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams const SkBitmap& bitmap(*nativeBitmap); 40098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 40198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams bitmap.lockPixels(); 40298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams const void* ptr = bitmap.getPixels(); 40398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint id = (jint)rsAllocationCubeCreateFromBitmap(con, 40498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (RsType)type, (RsAllocationMipmapControl)mip, 40598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams ptr, bitmap.getSize(), usage); 40698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams bitmap.unlockPixels(); 40798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return id; 40898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 40998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 41098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 41198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap) 41298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 41398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams SkBitmap const * nativeBitmap = 41498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 41598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams const SkBitmap& bitmap(*nativeBitmap); 41698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int w = bitmap.width(); 41798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams int h = bitmap.height(); 41898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 41998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams bitmap.lockPixels(); 42098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams const void* ptr = bitmap.getPixels(); 42198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocation2DData(con, (RsAllocation)alloc, 0, 0, 42298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, 42398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams w, h, ptr, bitmap.getSize()); 42498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams bitmap.unlockPixels(); 42598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 42698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 42798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 42898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap) 42998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 43098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams SkBitmap const * nativeBitmap = 43198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 43298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams const SkBitmap& bitmap(*nativeBitmap); 43398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 43498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams bitmap.lockPixels(); 43598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams void* ptr = bitmap.getPixels(); 43698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize()); 43798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams bitmap.unlockPixels(); 43898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams bitmap.notifyPixelsChanged(); 43998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 44098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 44198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void ReleaseBitmapCallback(void *bmp) 44298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 44398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams SkBitmap const * nativeBitmap = (SkBitmap const *)bmp; 44498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams nativeBitmap->unlockPixels(); 44598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 44698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 44798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 44898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 44998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationData1D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jintArray data, int sizeBytes) 45098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 45198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 45298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocation1DData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 45398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint *ptr = _env->GetIntArrayElements(data, NULL); 45498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 45598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 45698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 45798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 45898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 45998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationData1D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jshortArray data, int sizeBytes) 46098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 46198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 46298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocation1DData_s, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 46398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jshort *ptr = _env->GetShortArrayElements(data, NULL); 46498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 46598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 46698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 46798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 46898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 46998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationData1D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jbyteArray data, int sizeBytes) 47098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 47198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 47298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocation1DData_b, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 47398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jbyte *ptr = _env->GetByteArrayElements(data, NULL); 47498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 47598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 47698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 47798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 47898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 47998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationData1D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint count, jfloatArray data, int sizeBytes) 48098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 48198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 48298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocation1DData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, count, len, sizeBytes); 48398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 48498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocation1DData(con, (RsAllocation)alloc, offset, lod, count, ptr, sizeBytes); 48598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 48698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 48798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 48898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 48998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// native void rsnAllocationElementData1D(int con, int id, int xoff, int compIdx, byte[] d, int sizeBytes); 49098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationElementData1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint offset, jint lod, jint compIdx, jbyteArray data, int sizeBytes) 49198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 49298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 49398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes); 49498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jbyte *ptr = _env->GetByteArrayElements(data, NULL); 49598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocation1DElementData(con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx); 49698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 49798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 49898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 49998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 50098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationData2D_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 50198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint w, jint h, jshortArray data, int sizeBytes) 50298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 50398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 50498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 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); 50598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jshort *ptr = _env->GetShortArrayElements(data, NULL); 50698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes); 50798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseShortArrayElements(data, ptr, JNI_ABORT); 50898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 50998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 51098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 51198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationData2D_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 51298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint w, jint h, jbyteArray data, int sizeBytes) 51398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 51498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 51598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 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); 51698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jbyte *ptr = _env->GetByteArrayElements(data, NULL); 51798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes); 51898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 51998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 52098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 52198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 52298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationData2D_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 52398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint w, jint h, jintArray data, int sizeBytes) 52498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 52598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 52698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 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); 52798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint *ptr = _env->GetIntArrayElements(data, NULL); 52898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes); 52998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 53098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 53198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 53298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 53398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationData2D_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint xoff, jint yoff, jint lod, jint face, 53498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint w, jint h, jfloatArray data, int sizeBytes) 53598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 53698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 53798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 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); 53898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 53998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocation2DData(con, (RsAllocation)alloc, xoff, yoff, lod, (RsAllocationCubemapFace)face, w, h, ptr, sizeBytes); 54098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 54198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 54298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 54398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 54498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationData2D_alloc(JNIEnv *_env, jobject _this, RsContext con, 54598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint dstAlloc, jint dstXoff, jint dstYoff, 54698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint dstMip, jint dstFace, 54798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint width, jint height, 54898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint srcAlloc, jint srcXoff, jint srcYoff, 54998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint srcMip, jint srcFace) 55098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 55198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," 55298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams " dstMip(%i), dstFace(%i), width(%i), height(%i)," 55398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)", 55498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace, 55598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace); 55698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 55798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocationCopy2DRange(con, 55898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (RsAllocation)dstAlloc, 55998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams dstXoff, dstYoff, 56098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams dstMip, dstFace, 56198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams width, height, 56298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (RsAllocation)srcAlloc, 56398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams srcXoff, srcYoff, 56498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams srcMip, srcFace); 56598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 56698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 56798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 56898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationRead_i(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jintArray data) 56998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 57098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 57198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 57298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint *ptr = _env->GetIntArrayElements(data, NULL); 57398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jsize length = _env->GetArrayLength(data); 57498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(int)); 57598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseIntArrayElements(data, ptr, 0); 57698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 57798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 57898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 57998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationRead_s(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jshortArray data) 58098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 58198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 58298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 58398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jshort *ptr = _env->GetShortArrayElements(data, NULL); 58498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jsize length = _env->GetArrayLength(data); 58598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(short)); 58698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseShortArrayElements(data, ptr, 0); 58798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 58898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 58998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 59098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationRead_b(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jbyteArray data) 59198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 59298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 59398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocationRead_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 59498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jbyte *ptr = _env->GetByteArrayElements(data, NULL); 59598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jsize length = _env->GetArrayLength(data); 59698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(char)); 59798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseByteArrayElements(data, ptr, 0); 59898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 59998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 60098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 60198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationRead_f(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jfloatArray data) 60298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 60398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 60498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocationRead_f, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 60598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 60698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jsize length = _env->GetArrayLength(data); 60798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocationRead(con, (RsAllocation)alloc, ptr, length * sizeof(float)); 60898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseFloatArrayElements(data, ptr, 0); 60998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 61098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 61198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jint 61298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationGetType(JNIEnv *_env, jobject _this, RsContext con, jint a) 61398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 61498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocationGetType, con(%p), a(%p)", con, (RsAllocation)a); 61598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return (jint) rsaAllocationGetType(con, (RsAllocation)a); 61698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 61798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 61898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 61998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationResize1D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX) 62098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 62198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", con, (RsAllocation)alloc, dimX); 62298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocationResize1D(con, (RsAllocation)alloc, dimX); 62398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 62498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 62598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 62698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnAllocationResize2D(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jint dimX, jint dimY) 62798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 62898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i), sizeY(%i)", con, (RsAllocation)alloc, dimX, dimY); 62998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsAllocationResize2D(con, (RsAllocation)alloc, dimX, dimY); 63098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 63198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 63298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// ----------------------------------- 63398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 63498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 63598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptBindAllocation(JNIEnv *_env, jobject _this, RsContext con, jint script, jint alloc, jint slot) 63698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 63798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot); 63898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsScriptBindAllocation(con, (RsScript)script, (RsAllocation)alloc, slot); 63998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 64098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 64198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 64298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val) 64398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 64498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val); 64598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsScriptSetVarI(con, (RsScript)script, slot, val); 64698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 64798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 64898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 64998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val) 65098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 65198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", con, (void *)script, slot, val); 65298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsScriptSetVarObj(con, (RsScript)script, slot, (RsObjectBase)val); 65398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 65498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 65598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 65698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jlong val) 65798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 65898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", con, (void *)script, slot, val); 65998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsScriptSetVarJ(con, (RsScript)script, slot, val); 66098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 66198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 66298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 66398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val) 66498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 66598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", con, (void *)script, slot, val); 66698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsScriptSetVarF(con, (RsScript)script, slot, val); 66798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 66898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 66998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 67098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val) 67198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 67298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", con, (void *)script, slot, val); 67398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsScriptSetVarD(con, (RsScript)script, slot, val); 67498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 67598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 67698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 67798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data) 67898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 67998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 68098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 68198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jbyte *ptr = _env->GetByteArrayElements(data, NULL); 68298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsScriptSetVarV(con, (RsScript)script, slot, ptr, len); 68398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 68498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 68598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 68698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 68798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims) 68898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 68998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 69098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 69198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jbyte *ptr = _env->GetByteArrayElements(data, NULL); 69298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint dimsLen = _env->GetArrayLength(dims) * sizeof(int); 69398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint *dimsPtr = _env->GetIntArrayElements(dims, NULL); 69498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsScriptSetVarVE(con, (RsScript)script, slot, ptr, len, (RsElement)elem, 69598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (const size_t*) dimsPtr, dimsLen); 69698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 69798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseIntArrayElements(dims, dimsPtr, JNI_ABORT); 69898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 69998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 70098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 70198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 70298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptSetTimeZone(JNIEnv *_env, jobject _this, RsContext con, jint script, jbyteArray timeZone) 70398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 70498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptCSetTimeZone, con(%p), s(%p), timeZone(%s)", con, (void *)script, (const char *)timeZone); 70598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 70698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint length = _env->GetArrayLength(timeZone); 70798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jbyte* timeZone_ptr; 70898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams timeZone_ptr = (jbyte *) _env->GetPrimitiveArrayCritical(timeZone, (jboolean *)0); 70998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 71098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsScriptSetTimeZone(con, (RsScript)script, (const char *)timeZone_ptr, length); 71198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 71298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if (timeZone_ptr) { 71398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleasePrimitiveArrayCritical(timeZone, timeZone_ptr, 0); 71498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 71598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 71698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 71798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 71898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptInvoke(JNIEnv *_env, jobject _this, RsContext con, jint obj, jint slot) 71998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 72098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptInvoke, con(%p), script(%p)", con, (void *)obj); 72198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsScriptInvoke(con, (RsScript)obj, slot); 72298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 72398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 72498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 72598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptInvokeV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data) 72698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 72798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 72898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(data); 72998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jbyte *ptr = _env->GetByteArrayElements(data, NULL); 73098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsScriptInvokeV(con, (RsScript)script, slot, ptr, len); 73198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); 73298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 73398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 73498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 73598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptForEach(JNIEnv *_env, jobject _this, RsContext con, 73698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint script, jint slot, jint ain, jint aout) 73798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 73898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 73998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0); 74098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 74198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic void 74298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptForEachV(JNIEnv *_env, jobject _this, RsContext con, 74398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint script, jint slot, jint ain, jint aout, jbyteArray params) 74498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 74598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", con, (void *)script, slot); 74698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint len = _env->GetArrayLength(params); 74798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jbyte *ptr = _env->GetByteArrayElements(params, NULL); 74898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams rsScriptForEach(con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len); 74998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); 75098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 75198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 75298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 75398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// ----------------------------------- 75498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 75598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jint 75698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnScriptCCreate(JNIEnv *_env, jobject _this, RsContext con, 75798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jstring resName, jstring cacheDir, 75898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jbyteArray scriptRef, jint length) 75998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 76098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nScriptCCreate, con(%p)", con); 76198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 76298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams AutoJavaStringToUTF8 resNameUTF(_env, resName); 76398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); 76498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint ret = 0; 76598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jbyte* script_ptr = NULL; 76698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint _exception = 0; 76798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint remaining; 76898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if (!scriptRef) { 76998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _exception = 1; 77098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams //jniThrowException(_env, "java/lang/IllegalArgumentException", "script == null"); 77198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams goto exit; 77298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 77398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if (length < 0) { 77498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _exception = 1; 77598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams //jniThrowException(_env, "java/lang/IllegalArgumentException", "length < 0"); 77698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams goto exit; 77798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 77898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams remaining = _env->GetArrayLength(scriptRef); 77998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if (remaining < length) { 78098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _exception = 1; 78198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams //jniThrowException(_env, "java/lang/IllegalArgumentException", 78298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams // "length > script.length - offset"); 78398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams goto exit; 78498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 78598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams script_ptr = (jbyte *) 78698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); 78798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 78898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams //rsScriptCSetText(con, (const char *)script_ptr, length); 78998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 79098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams ret = (jint)rsScriptCCreate(con, 79198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams resNameUTF.c_str(), resNameUTF.length(), 79298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams cacheDirUTF.c_str(), cacheDirUTF.length(), 79398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (const char *)script_ptr, length); 79498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 79598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsexit: 79698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if (script_ptr) { 79798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env->ReleasePrimitiveArrayCritical(scriptRef, script_ptr, 79898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _exception ? JNI_ABORT: 0); 79998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 80098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 80198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return ret; 80298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 80398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 80498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// --------------------------------------------------------------------------- 80598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 80698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jint 80798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnProgramRasterCreate(JNIEnv *_env, jobject _this, RsContext con, jboolean pointSprite, jint cull) 80898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 80998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", con, pointSprite, cull); 81098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return (jint)rsProgramRasterCreate(con, pointSprite, (RsCullMode)cull); 81198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 81298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 81398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 81498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// --------------------------------------------------------------------------- 81598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 81698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic jint 81798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason SamsnSamplerCreate(JNIEnv *_env, jobject _this, RsContext con, jint magFilter, jint minFilter, 81898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint wrapS, jint wrapT, jint wrapR, jfloat aniso) 81998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 82098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams LOG_API("nSamplerCreate, con(%p)", con); 82198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return (jint)rsSamplerCreate(con, 82298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (RsSamplerValue)magFilter, 82398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (RsSamplerValue)minFilter, 82498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (RsSamplerValue)wrapS, 82598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (RsSamplerValue)wrapT, 82698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams (RsSamplerValue)wrapR, 82798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams aniso); 82898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 82998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 83098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// --------------------------------------------------------------------------- 83198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 83298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 83398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic const char *classPathName = "android/support/v8/renderscript/RenderScript"; 83498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 83598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic JNINativeMethod methods[] = { 83698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"_nInit", "()V", (void*)_nInit }, 83798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 83898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"nDeviceCreate", "()I", (void*)nDeviceCreate }, 83998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy }, 84098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"nDeviceSetConfig", "(III)V", (void*)nDeviceSetConfig }, 84198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"nContextGetUserMessage", "(I[I)I", (void*)nContextGetUserMessage }, 84298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"nContextGetErrorMessage", "(I)Ljava/lang/String;", (void*)nContextGetErrorMessage }, 84398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"nContextPeekMessage", "(I[I)I", (void*)nContextPeekMessage }, 84498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 84598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"nContextInitToClient", "(I)V", (void*)nContextInitToClient }, 84698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"nContextDeinitToClient", "(I)V", (void*)nContextDeinitToClient }, 84798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 84898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 84998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// All methods below are thread protected in java. 85098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnContextCreate", "(III)I", (void*)nContextCreate }, 85198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnContextFinish", "(I)V", (void*)nContextFinish }, 85298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnContextSetPriority", "(II)V", (void*)nContextSetPriority }, 85398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnContextDestroy", "(I)V", (void*)nContextDestroy }, 85498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnContextDump", "(II)V", (void*)nContextDump }, 85598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnObjDestroy", "(II)V", (void*)nObjDestroy }, 85698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 85798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnElementCreate", "(IIIZI)I", (void*)nElementCreate }, 85898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnElementCreate2", "(I[I[Ljava/lang/String;[I)I", (void*)nElementCreate2 }, 85998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnElementGetSubElements", "(II[I[Ljava/lang/String;[I)V", (void*)nElementGetSubElements }, 86098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 86198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnTypeCreate", "(IIIIIZZ)I", (void*)nTypeCreate }, 86298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 86398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationCreateTyped", "(IIIII)I", (void*)nAllocationCreateTyped }, 86498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationCreateFromBitmap", "(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCreateFromBitmap }, 86598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationCubeCreateFromBitmap","(IIILandroid/graphics/Bitmap;I)I", (void*)nAllocationCubeCreateFromBitmap }, 86698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 86798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationCopyFromBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap }, 86898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap }, 86998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 87098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll }, 87198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i }, 87298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s }, 87398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b }, 87498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationData1D", "(IIIII[FI)V", (void*)nAllocationData1D_f }, 87598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationElementData1D", "(IIIII[BI)V", (void*)nAllocationElementData1D }, 87698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationData2D", "(IIIIIIII[II)V", (void*)nAllocationData2D_i }, 87798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationData2D", "(IIIIIIII[SI)V", (void*)nAllocationData2D_s }, 87898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationData2D", "(IIIIIIII[BI)V", (void*)nAllocationData2D_b }, 87998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationData2D", "(IIIIIIII[FI)V", (void*)nAllocationData2D_f }, 88098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationData2D", "(IIIIIIIIIIIII)V", (void*)nAllocationData2D_alloc }, 88198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationRead", "(II[I)V", (void*)nAllocationRead_i }, 88298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationRead", "(II[S)V", (void*)nAllocationRead_s }, 88398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationRead", "(II[B)V", (void*)nAllocationRead_b }, 88498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationRead", "(II[F)V", (void*)nAllocationRead_f }, 88598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationGetType", "(II)I", (void*)nAllocationGetType}, 88698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationResize1D", "(III)V", (void*)nAllocationResize1D }, 88798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationResize2D", "(IIII)V", (void*)nAllocationResize2D }, 88898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnAllocationGenerateMipmaps", "(II)V", (void*)nAllocationGenerateMipmaps }, 88998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 89098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptBindAllocation", "(IIII)V", (void*)nScriptBindAllocation }, 89198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptSetTimeZone", "(II[B)V", (void*)nScriptSetTimeZone }, 89298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptInvoke", "(III)V", (void*)nScriptInvoke }, 89398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptInvokeV", "(III[B)V", (void*)nScriptInvokeV }, 89498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptForEach", "(IIIII)V", (void*)nScriptForEach }, 89598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptForEach", "(IIIII[B)V", (void*)nScriptForEachV }, 89698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI }, 89798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ }, 89898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF }, 89998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD }, 90098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV }, 90198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptSetVarVE", "(III[BI[I)V", (void*)nScriptSetVarVE }, 90298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj }, 90398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 90498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnScriptCCreate", "(ILjava/lang/String;Ljava/lang/String;[BI)I", (void*)nScriptCCreate }, 90598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 90698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{"rsnSamplerCreate", "(IIIIIIF)I", (void*)nSamplerCreate }, 90798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 90898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams}; 90998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 91098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsstatic int registerFuncs(JNIEnv *_env) 91198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 91298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return android::AndroidRuntime::registerNativeMethods( 91398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams _env, classPathName, methods, NELEM(methods)); 91498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 91598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 91698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams// --------------------------------------------------------------------------- 91798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 91898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsjint JNI_OnLoad(JavaVM* vm, void* reserved) 91998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams{ 92098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams JNIEnv* env = NULL; 92198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams jint result = -1; 92298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 92398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { 92498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams ALOGE("ERROR: GetEnv failed\n"); 92598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams goto bail; 92698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 92798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams assert(env != NULL); 92898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 92998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams if (registerFuncs(env) < 0) { 93098a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams ALOGE("ERROR: MediaPlayer native registration failed\n"); 93198a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams goto bail; 93298a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams } 93398a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 93498a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams /* success -- return valid version number */ 93598a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams result = JNI_VERSION_1_4; 93698a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams 93798a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Samsbail: 93898a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams return result; 93998a281354fe06d1f970d0521c9a08d9eb0aa1a45Jason Sams} 940