android_renderscript_RenderScript.cpp revision e29d471e5ca9781d8772d445ec7832e94856fd14
1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#define LOG_TAG "libRS_jni" 18 19#include <stdlib.h> 20#include <stdio.h> 21#include <fcntl.h> 22#include <unistd.h> 23#include <math.h> 24#include <utils/misc.h> 25 26#include <ui/Surface.h> 27 28#include <core/SkBitmap.h> 29 30 31#include "jni.h" 32#include "JNIHelp.h" 33#include "android_runtime/AndroidRuntime.h" 34 35#include <RenderScript.h> 36#include <RenderScriptEnv.h> 37 38//#define LOG_API LOGE 39#define LOG_API(...) 40 41using namespace android; 42 43// --------------------------------------------------------------------------- 44 45static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL) 46{ 47 jclass npeClazz = env->FindClass(exc); 48 env->ThrowNew(npeClazz, msg); 49} 50 51static jfieldID gContextId = 0; 52static jfieldID gNativeBitmapID = 0; 53 54static void _nInit(JNIEnv *_env, jclass _this) 55{ 56 gContextId = _env->GetFieldID(_this, "mContext", "I"); 57 58 jclass bitmapClass = _env->FindClass("android/graphics/Bitmap"); 59 gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I"); 60} 61 62 63// --------------------------------------------------------------------------- 64 65static void 66nAssignName(JNIEnv *_env, jobject _this, jint obj, jbyteArray str) 67{ 68 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 69 LOG_API("nAssignName, con(%p), obj(%p)", con, obj); 70 71 jint len = _env->GetArrayLength(str); 72 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); 73 rsAssignName((void *)obj, (const char *)cptr, len); 74 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); 75} 76 77 78static jint 79nFileOpen(JNIEnv *_env, jobject _this, jbyteArray str) 80{ 81 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 82 LOG_API("nFileOpen, con(%p)", con); 83 84 jint len = _env->GetArrayLength(str); 85 jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); 86 jint ret = (jint)rsFileOpen((const char *)cptr, len); 87 _env->ReleasePrimitiveArrayCritical(str, cptr, JNI_ABORT); 88 return ret; 89} 90 91// --------------------------------------------------------------------------- 92 93static jint 94nDeviceCreate(JNIEnv *_env, jobject _this) 95{ 96 LOG_API("nDeviceCreate"); 97 return (jint)rsDeviceCreate(); 98} 99 100static void 101nDeviceDestroy(JNIEnv *_env, jobject _this, jint dev) 102{ 103 LOG_API("nDeviceDestroy"); 104 return rsDeviceDestroy((RsDevice)dev); 105} 106 107static jint 108nContextCreate(JNIEnv *_env, jobject _this, jint dev, jobject wnd, jint ver) 109{ 110 LOG_API("nContextCreate"); 111 112 if (wnd == NULL) { 113 not_valid_surface: 114 doThrow(_env, "java/lang/IllegalArgumentException", 115 "Make sure the SurfaceView or associated SurfaceHolder has a valid Surface"); 116 return 0; 117 } 118 jclass surface_class = _env->FindClass("android/view/Surface"); 119 jfieldID surfaceFieldID = _env->GetFieldID(surface_class, "mSurface", "I"); 120 Surface * window = (Surface*)_env->GetIntField(wnd, surfaceFieldID); 121 if (window == NULL) 122 goto not_valid_surface; 123 124 return (jint)rsContextCreate((RsDevice)dev, window, ver); 125} 126 127static void 128nContextDestroy(JNIEnv *_env, jobject _this, jint con) 129{ 130 LOG_API("nContextDestroy, con(%p)", (RsContext)con); 131 return rsContextDestroy((RsContext)con); 132} 133 134 135static void 136nElementBegin(JNIEnv *_env, jobject _this) 137{ 138 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 139 LOG_API("nElementBegin, con(%p)", con); 140 rsElementBegin(); 141} 142 143static void 144nElementAddPredefined(JNIEnv *_env, jobject _this, jint predef) 145{ 146 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 147 LOG_API("nElementAddPredefined, con(%p), predef(%i)", con, predef); 148 rsElementAddPredefined((RsElementPredefined)predef); 149} 150 151static void 152nElementAdd(JNIEnv *_env, jobject _this, jint kind, jint type, jint norm, jint bits) 153{ 154 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 155 LOG_API("nElementAdd, con(%p), kind(%i), type(%i), norm(%i), bits(%i)", con, kind, type, norm, bits); 156 rsElementAdd((RsDataKind)kind, (RsDataType)type, norm != 0, (size_t)bits); 157} 158 159static jint 160nElementCreate(JNIEnv *_env, jobject _this) 161{ 162 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 163 LOG_API("nElementCreate, con(%p)", con); 164 return (jint)rsElementCreate(); 165} 166 167static jint 168nElementGetPredefined(JNIEnv *_env, jobject _this, jint predef) 169{ 170 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 171 LOG_API("nElementGetPredefined, con(%p) predef(%i)", con, predef); 172 return (jint)rsElementGetPredefined((RsElementPredefined)predef); 173} 174 175static void 176nElementDestroy(JNIEnv *_env, jobject _this, jint e) 177{ 178 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 179 LOG_API("nElementDestroy, con(%p) e(%p)", con, (RsElement)e); 180 rsElementDestroy((RsElement)e); 181} 182 183// ----------------------------------- 184 185static void 186nTypeBegin(JNIEnv *_env, jobject _this, jint eID) 187{ 188 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 189 LOG_API("nTypeBegin, con(%p) e(%p)", con, (RsElement)eID); 190 rsTypeBegin((RsElement)eID); 191} 192 193static void 194nTypeAdd(JNIEnv *_env, jobject _this, jint dim, jint val) 195{ 196 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 197 LOG_API("nTypeAdd, con(%p) dim(%i), val(%i)", con, dim, val); 198 rsTypeAdd((RsDimension)dim, val); 199} 200 201static jint 202nTypeCreate(JNIEnv *_env, jobject _this) 203{ 204 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 205 LOG_API("nTypeCreate, con(%p)", con); 206 return (jint)rsTypeCreate(); 207} 208 209static void 210nTypeDestroy(JNIEnv *_env, jobject _this, jint eID) 211{ 212 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 213 LOG_API("nTypeDestroy, con(%p), t(%p)", con, (RsType)eID); 214 rsTypeDestroy((RsType)eID); 215} 216 217// ----------------------------------- 218 219static jint 220nAllocationCreateTyped(JNIEnv *_env, jobject _this, jint e) 221{ 222 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 223 LOG_API("nAllocationCreateTyped, con(%p), e(%p)", con, (RsElement)e); 224 return (jint) rsAllocationCreateTyped((RsElement)e); 225} 226 227static jint 228nAllocationCreatePredefSized(JNIEnv *_env, jobject _this, jint predef, jint count) 229{ 230 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 231 LOG_API("nAllocationCreatePredefSized, con(%p), predef(%i), count(%i)", con, predef, count); 232 return (jint) rsAllocationCreatePredefSized((RsElementPredefined)predef, count); 233} 234 235static jint 236nAllocationCreateSized(JNIEnv *_env, jobject _this, jint e, jint count) 237{ 238 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 239 LOG_API("nAllocationCreateSized, con(%p), e(%p), count(%i)", con, (RsElement)e, count); 240 return (jint) rsAllocationCreateSized((RsElement)e, count); 241} 242 243static void 244nAllocationUploadToTexture(JNIEnv *_env, jobject _this, jint a, jint mip) 245{ 246 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 247 LOG_API("nAllocationUploadToTexture, con(%p), a(%p), mip(%i)", con, (RsAllocation)a, mip); 248 rsAllocationUploadToTexture((RsAllocation)a, mip); 249} 250 251static RsElementPredefined SkBitmapToPredefined(SkBitmap::Config cfg) 252{ 253 switch (cfg) { 254 case SkBitmap::kA8_Config: 255 return RS_ELEMENT_A_8; 256 case SkBitmap::kARGB_4444_Config: 257 return RS_ELEMENT_RGBA_4444; 258 case SkBitmap::kARGB_8888_Config: 259 return RS_ELEMENT_RGBA_8888; 260 case SkBitmap::kRGB_565_Config: 261 return RS_ELEMENT_RGB_565; 262 263 default: 264 break; 265 } 266 // If we don't have a conversion mark it as a user type. 267 LOGE("Unsupported bitmap type"); 268 return RS_ELEMENT_USER_U8; 269} 270 271static int 272nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jint dstFmt, jboolean genMips, jobject jbitmap) 273{ 274 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 275 SkBitmap const * nativeBitmap = 276 (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID); 277 const SkBitmap& bitmap(*nativeBitmap); 278 SkBitmap::Config config = bitmap.getConfig(); 279 280 RsElementPredefined e = SkBitmapToPredefined(config); 281 282 if (e != RS_ELEMENT_USER_U8) { 283 bitmap.lockPixels(); 284 const int w = bitmap.width(); 285 const int h = bitmap.height(); 286 const void* ptr = bitmap.getPixels(); 287 jint id = (jint)rsAllocationCreateFromBitmap(w, h, (RsElementPredefined)dstFmt, e, genMips, ptr); 288 bitmap.unlockPixels(); 289 return id; 290 } 291 return 0; 292} 293 294 295static void 296nAllocationDestroy(JNIEnv *_env, jobject _this, jint a) 297{ 298 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 299 LOG_API("nAllocationDestroy, con(%p), a(%p)", con, (RsAllocation)a); 300 rsAllocationDestroy((RsAllocation)a); 301} 302 303static void 304nAllocationData_i(JNIEnv *_env, jobject _this, jint alloc, jintArray data) 305{ 306 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 307 jint len = _env->GetArrayLength(data); 308 LOG_API("nAllocationData_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 309 jint *ptr = _env->GetIntArrayElements(data, NULL); 310 rsAllocationData((RsAllocation)alloc, ptr); 311 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 312} 313 314static void 315nAllocationData_f(JNIEnv *_env, jobject _this, jint alloc, jfloatArray data) 316{ 317 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 318 jint len = _env->GetArrayLength(data); 319 LOG_API("nAllocationData_i, con(%p), alloc(%p), len(%i)", con, (RsAllocation)alloc, len); 320 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 321 rsAllocationData((RsAllocation)alloc, ptr); 322 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 323} 324 325static void 326nAllocationSubData1D_i(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jintArray data) 327{ 328 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 329 jint len = _env->GetArrayLength(data); 330 LOG_API("nAllocation1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAllocation)alloc, offset, count, len); 331 jint *ptr = _env->GetIntArrayElements(data, NULL); 332 rsAllocation1DSubData((RsAllocation)alloc, offset, count, ptr); 333 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 334} 335 336static void 337nAllocationSubData1D_f(JNIEnv *_env, jobject _this, jint alloc, jint offset, jint count, jfloatArray data) 338{ 339 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 340 jint len = _env->GetArrayLength(data); 341 LOG_API("nAllocation1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAllocation)alloc, offset, count, len); 342 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 343 rsAllocation1DSubData((RsAllocation)alloc, offset, count, ptr); 344 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 345} 346 347static void 348nAllocationSubData2D_i(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jintArray data) 349{ 350 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 351 jint len = _env->GetArrayLength(data); 352 LOG_API("nAllocation2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); 353 jint *ptr = _env->GetIntArrayElements(data, NULL); 354 rsAllocation2DSubData((RsAllocation)alloc, xoff, yoff, w, h, ptr); 355 _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); 356} 357 358static void 359nAllocationSubData2D_f(JNIEnv *_env, jobject _this, jint alloc, jint xoff, jint yoff, jint w, jint h, jfloatArray data) 360{ 361 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 362 jint len = _env->GetArrayLength(data); 363 LOG_API("nAllocation2DSubData_i, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i)", con, (RsAllocation)alloc, xoff, yoff, w, h, len); 364 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 365 rsAllocation2DSubData((RsAllocation)alloc, xoff, yoff, w, h, ptr); 366 _env->ReleaseFloatArrayElements(data, ptr, JNI_ABORT); 367} 368 369 370 371// ----------------------------------- 372 373static void 374nTriangleMeshDestroy(JNIEnv *_env, jobject _this, jint tm) 375{ 376 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 377 LOG_API("nTriangleMeshDestroy, con(%p), tm(%p)", con, (RsAllocation)tm); 378 rsTriangleMeshDestroy((RsTriangleMesh)tm); 379} 380 381static void 382nTriangleMeshBegin(JNIEnv *_env, jobject _this, jint v, jint i) 383{ 384 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 385 LOG_API("nTriangleMeshBegin, con(%p), vertex(%p), index(%p)", con, (RsElement)v, (RsElement)i); 386 rsTriangleMeshBegin((RsElement)v, (RsElement)i); 387} 388 389static void 390nTriangleMeshAddVertex_XY(JNIEnv *_env, jobject _this, jfloat x, jfloat y) 391{ 392 float v[] = {x, y}; 393 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 394 LOG_API("nTriangleMeshAddVertex_XY, con(%p), x(%f), y(%f)", con, x, y); 395 rsTriangleMeshAddVertex(v); 396} 397 398static void 399nTriangleMeshAddVertex_XYZ(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z) 400{ 401 float v[] = {x, y, z}; 402 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 403 LOG_API("nTriangleMeshAddVertex_XYZ, con(%p), x(%f), y(%f), z(%f)", con, x, y, z); 404 rsTriangleMeshAddVertex(v); 405} 406 407static void 408nTriangleMeshAddVertex_XY_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat s, jfloat t) 409{ 410 float v[] = {s, t, x, y}; 411 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 412 LOG_API("nTriangleMeshAddVertex_XY_ST, con(%p), x(%f), y(%f), s(%f), t(%f)", con, x, y, s, t); 413 rsTriangleMeshAddVertex(v); 414} 415 416static void 417nTriangleMeshAddVertex_XYZ_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t) 418{ 419 float v[] = {s, t, x, y, z}; 420 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 421 LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t); 422 rsTriangleMeshAddVertex(v); 423} 424 425static void 426nTriangleMeshAddVertex_XYZ_ST_NORM(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t, jfloat nx, jfloat ny, jfloat nz) 427{ 428 float v[] = {nx, ny, nz, s, t, x, y, z}; 429 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 430 LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t); 431 rsTriangleMeshAddVertex(v); 432} 433 434static void 435nTriangleMeshAddTriangle(JNIEnv *_env, jobject _this, jint i1, jint i2, jint i3) 436{ 437 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 438 LOG_API("nTriangleMeshAddTriangle, con(%p), i1(%i), i2(%i), i3(%i)", con, i1, i2, i3); 439 rsTriangleMeshAddTriangle(i1, i2, i3); 440} 441 442static jint 443nTriangleMeshCreate(JNIEnv *_env, jobject _this) 444{ 445 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 446 LOG_API("nTriangleMeshCreate, con(%p)", con); 447 return (jint) rsTriangleMeshCreate(); 448} 449 450// ----------------------------------- 451 452static void 453nAdapter1DDestroy(JNIEnv *_env, jobject _this, jint adapter) 454{ 455 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 456 LOG_API("nAdapter1DDestroy, con(%p), adapter(%p)", con, (RsAdapter1D)adapter); 457 rsAdapter1DDestroy((RsAdapter1D)adapter); 458} 459 460static void 461nAdapter1DBindAllocation(JNIEnv *_env, jobject _this, jint adapter, jint alloc) 462{ 463 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 464 LOG_API("nAdapter1DBindAllocation, con(%p), adapter(%p), alloc(%p)", con, (RsAdapter1D)adapter, (RsAllocation)alloc); 465 rsAdapter1DBindAllocation((RsAdapter1D)adapter, (RsAllocation)alloc); 466} 467 468static void 469nAdapter1DSetConstraint(JNIEnv *_env, jobject _this, jint adapter, jint dim, jint value) 470{ 471 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 472 LOG_API("nAdapter1DSetConstraint, con(%p), adapter(%p), dim(%i), value(%i)", con, (RsAdapter1D)adapter, dim, value); 473 rsAdapter1DSetConstraint((RsAdapter1D)adapter, (RsDimension)dim, value); 474} 475 476static void 477nAdapter1DData_i(JNIEnv *_env, jobject _this, jint adapter, jintArray data) 478{ 479 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 480 jint len = _env->GetArrayLength(data); 481 LOG_API("nAdapter1DData_i, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len); 482 jint *ptr = _env->GetIntArrayElements(data, NULL); 483 rsAdapter1DData((RsAdapter1D)adapter, ptr); 484 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); 485} 486 487static void 488nAdapter1DSubData_i(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jintArray data) 489{ 490 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 491 jint len = _env->GetArrayLength(data); 492 LOG_API("nAdapter1DSubData_i, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len); 493 jint *ptr = _env->GetIntArrayElements(data, NULL); 494 rsAdapter1DSubData((RsAdapter1D)adapter, offset, count, ptr); 495 _env->ReleaseIntArrayElements(data, ptr, 0/*JNI_ABORT*/); 496} 497 498static void 499nAdapter1DData_f(JNIEnv *_env, jobject _this, jint adapter, jfloatArray data) 500{ 501 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 502 jint len = _env->GetArrayLength(data); 503 LOG_API("nAdapter1DData_f, con(%p), adapter(%p), len(%i)", con, (RsAdapter1D)adapter, len); 504 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 505 rsAdapter1DData((RsAdapter1D)adapter, ptr); 506 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); 507} 508 509static void 510nAdapter1DSubData_f(JNIEnv *_env, jobject _this, jint adapter, jint offset, jint count, jfloatArray data) 511{ 512 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 513 jint len = _env->GetArrayLength(data); 514 LOG_API("nAdapter1DSubData_f, con(%p), adapter(%p), offset(%i), count(%i), len(%i)", con, (RsAdapter1D)adapter, offset, count, len); 515 jfloat *ptr = _env->GetFloatArrayElements(data, NULL); 516 rsAdapter1DSubData((RsAdapter1D)adapter, offset, count, ptr); 517 _env->ReleaseFloatArrayElements(data, ptr, 0/*JNI_ABORT*/); 518} 519 520static jint 521nAdapter1DCreate(JNIEnv *_env, jobject _this) 522{ 523 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 524 LOG_API("nAdapter1DCreate, con(%p)", con); 525 return (jint)rsAdapter1DCreate(); 526} 527 528// ----------------------------------- 529 530static void 531nScriptDestroy(JNIEnv *_env, jobject _this, jint script) 532{ 533 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 534 LOG_API("nScriptDestroy, con(%p), script(%p)", con, (RsScript)script); 535 rsScriptDestroy((RsScript)script); 536} 537 538static void 539nScriptBindAllocation(JNIEnv *_env, jobject _this, jint script, jint alloc, jint slot) 540{ 541 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 542 LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", con, (RsScript)script, (RsAllocation)alloc, slot); 543 rsScriptBindAllocation((RsScript)script, (RsAllocation)alloc, slot); 544} 545 546static void 547nScriptCBegin(JNIEnv *_env, jobject _this) 548{ 549 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 550 LOG_API("nScriptCBegin, con(%p)", con); 551 rsScriptCBegin(); 552} 553 554static void 555nScriptCSetClearColor(JNIEnv *_env, jobject _this, jfloat r, jfloat g, jfloat b, jfloat a) 556{ 557 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 558 LOG_API("nScriptCSetClearColor, con(%p), r(%f), g(%f), b(%f), a(%f)", con, r, g, b, a); 559 rsScriptCSetClearColor(r, g, b, a); 560} 561 562static void 563nScriptCSetClearDepth(JNIEnv *_env, jobject _this, jfloat d) 564{ 565 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 566 LOG_API("nScriptCSetClearColor, con(%p), depth(%f)", con, d); 567 rsScriptCSetClearDepth(d); 568} 569 570static void 571nScriptCSetClearStencil(JNIEnv *_env, jobject _this, jint stencil) 572{ 573 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 574 LOG_API("nScriptCSetClearStencil, con(%p), stencil(%i)", con, stencil); 575 rsScriptCSetClearStencil(stencil); 576} 577 578static void 579nScriptCAddType(JNIEnv *_env, jobject _this, jint type) 580{ 581 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 582 LOG_API("nScriptCAddType, con(%p), type(%p)", con, (RsType)type); 583 rsScriptCAddType((RsType)type); 584} 585 586static void 587nScriptCSetRoot(JNIEnv *_env, jobject _this, jboolean isRoot) 588{ 589 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 590 LOG_API("nScriptCSetRoot, con(%p), isRoot(%i)", con, isRoot); 591 rsScriptCSetRoot(isRoot); 592} 593 594static void 595nScriptCSetScript(JNIEnv *_env, jobject _this, jbyteArray scriptRef, 596 jint offset, jint length) 597{ 598 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 599 LOG_API("!!! nScriptCSetScript, con(%p)", con); 600 jint _exception = 0; 601 jint remaining; 602 jbyte* script_base = 0; 603 jbyte* script_ptr; 604 if (!scriptRef) { 605 _exception = 1; 606 //_env->ThrowNew(IAEClass, "script == null"); 607 goto exit; 608 } 609 if (offset < 0) { 610 _exception = 1; 611 //_env->ThrowNew(IAEClass, "offset < 0"); 612 goto exit; 613 } 614 if (length < 0) { 615 _exception = 1; 616 //_env->ThrowNew(IAEClass, "length < 0"); 617 goto exit; 618 } 619 remaining = _env->GetArrayLength(scriptRef) - offset; 620 if (remaining < length) { 621 _exception = 1; 622 //_env->ThrowNew(IAEClass, "length > script.length - offset"); 623 goto exit; 624 } 625 script_base = (jbyte *) 626 _env->GetPrimitiveArrayCritical(scriptRef, (jboolean *)0); 627 script_ptr = script_base + offset; 628 629 rsScriptCSetText((const char *)script_ptr, length); 630 631exit: 632 if (script_base) { 633 _env->ReleasePrimitiveArrayCritical(scriptRef, script_base, 634 _exception ? JNI_ABORT: 0); 635 } 636} 637 638static jint 639nScriptCCreate(JNIEnv *_env, jobject _this) 640{ 641 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 642 LOG_API("nScriptCCreate, con(%p)", con); 643 return (jint)rsScriptCCreate(); 644} 645 646// --------------------------------------------------------------------------- 647 648static void 649nProgramFragmentStoreBegin(JNIEnv *_env, jobject _this, jint in, jint out) 650{ 651 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 652 LOG_API("nProgramFragmentStoreBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out); 653 rsProgramFragmentStoreBegin((RsElement)in, (RsElement)out); 654} 655 656static void 657nProgramFragmentStoreDepthFunc(JNIEnv *_env, jobject _this, jint func) 658{ 659 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 660 LOG_API("nProgramFragmentStoreDepthFunc, con(%p), func(%i)", con, func); 661 rsProgramFragmentStoreDepthFunc((RsDepthFunc)func); 662} 663 664static void 665nProgramFragmentStoreDepthMask(JNIEnv *_env, jobject _this, jboolean enable) 666{ 667 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 668 LOG_API("nProgramFragmentStoreDepthMask, con(%p), enable(%i)", con, enable); 669 rsProgramFragmentStoreDepthMask(enable); 670} 671 672static void 673nProgramFragmentStoreColorMask(JNIEnv *_env, jobject _this, jboolean r, jboolean g, jboolean b, jboolean a) 674{ 675 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 676 LOG_API("nProgramFragmentStoreColorMask, con(%p), r(%i), g(%i), b(%i), a(%i)", con, r, g, b, a); 677 rsProgramFragmentStoreColorMask(r, g, b, a); 678} 679 680static void 681nProgramFragmentStoreBlendFunc(JNIEnv *_env, jobject _this, int src, int dst) 682{ 683 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 684 LOG_API("nProgramFragmentStoreBlendFunc, con(%p), src(%i), dst(%i)", con, src, dst); 685 rsProgramFragmentStoreBlendFunc((RsBlendSrcFunc)src, (RsBlendDstFunc)dst); 686} 687 688static void 689nProgramFragmentStoreDither(JNIEnv *_env, jobject _this, jboolean enable) 690{ 691 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 692 LOG_API("nProgramFragmentStoreDither, con(%p), enable(%i)", con, enable); 693 rsProgramFragmentStoreDither(enable); 694} 695 696static jint 697nProgramFragmentStoreCreate(JNIEnv *_env, jobject _this) 698{ 699 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 700 LOG_API("nProgramFragmentStoreCreate, con(%p)", con); 701 702 return (jint)rsProgramFragmentStoreCreate(); 703} 704 705static void 706nProgramFragmentStoreDestroy(JNIEnv *_env, jobject _this, jint pgm) 707{ 708 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 709 LOG_API("nProgramFragmentStoreDestroy, con(%p), pgm(%i)", con, pgm); 710 rsProgramFragmentStoreDestroy((RsProgramFragmentStore)pgm); 711} 712 713// --------------------------------------------------------------------------- 714 715static void 716nProgramFragmentBegin(JNIEnv *_env, jobject _this, jint in, jint out) 717{ 718 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 719 LOG_API("nProgramFragmentBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out); 720 rsProgramFragmentBegin((RsElement)in, (RsElement)out); 721} 722 723static void 724nProgramFragmentBindTexture(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a) 725{ 726 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 727 LOG_API("nProgramFragmentBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsAllocation)a); 728 rsProgramFragmentBindTexture((RsProgramFragment)vpf, slot, (RsAllocation)a); 729} 730 731static void 732nProgramFragmentBindSampler(JNIEnv *_env, jobject _this, jint vpf, jint slot, jint a) 733{ 734 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 735 LOG_API("nProgramFragmentBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramFragment)vpf, slot, (RsSampler)a); 736 rsProgramFragmentBindSampler((RsProgramFragment)vpf, slot, (RsSampler)a); 737} 738 739static void 740nProgramFragmentSetType(JNIEnv *_env, jobject _this, jint slot, jint vt) 741{ 742 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 743 LOG_API("nProgramFragmentSetType, con(%p), slot(%i), vt(%p)", con, slot, (RsType)vt); 744 rsProgramFragmentSetType(slot, (RsType)vt); 745} 746 747static void 748nProgramFragmentSetEnvMode(JNIEnv *_env, jobject _this, jint slot, jint env) 749{ 750 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 751 LOG_API("nProgramFragmentSetEnvMode, con(%p), slot(%i), vt(%i)", con, slot, env); 752 rsProgramFragmentSetEnvMode(slot, (RsTexEnvMode)env); 753} 754 755static void 756nProgramFragmentSetTexEnable(JNIEnv *_env, jobject _this, jint slot, jboolean enable) 757{ 758 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 759 LOG_API("nProgramFragmentSetTexEnable, con(%p), slot(%i), enable(%i)", con, slot, enable); 760 rsProgramFragmentSetTexEnable(slot, enable); 761} 762 763static jint 764nProgramFragmentCreate(JNIEnv *_env, jobject _this, jint slot, jboolean enable) 765{ 766 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 767 LOG_API("nProgramFragmentCreate, con(%p)", con); 768 return (jint)rsProgramFragmentCreate(); 769} 770 771static void 772nProgramFragmentDestroy(JNIEnv *_env, jobject _this, jint pgm) 773{ 774 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 775 LOG_API("nProgramFragmentDestroy, con(%p), pgm(%i)", con, pgm); 776 rsProgramFragmentDestroy((RsProgramFragment)pgm); 777} 778 779// --------------------------------------------------------------------------- 780 781static void 782nProgramVertexBegin(JNIEnv *_env, jobject _this, jint in, jint out) 783{ 784 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 785 LOG_API("nProgramVertexBegin, con(%p), in(%p), out(%p)", con, (RsElement)in, (RsElement)out); 786 rsProgramVertexBegin((RsElement)in, (RsElement)out); 787} 788 789static void 790nProgramVertexBindAllocation(JNIEnv *_env, jobject _this, jint vpv, jint slot, jint a) 791{ 792 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 793 LOG_API("nProgramVertexBindAllocation, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsAllocation)a); 794 rsProgramVertexBindAllocation((RsProgramFragment)vpv, slot, (RsAllocation)a); 795} 796 797static void 798nProgramVertexSetType(JNIEnv *_env, jobject _this, jint slot, jint t) 799{ 800 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 801 LOG_API("nProgramVertexSetType, con(%p), vpf(%p), slot(%i), a(%p)", con, (RsProgramVertex)vpv, slot, (RsType)t); 802 rsProgramVertexSetType(slot, (RsType)t); 803} 804 805static void 806nProgramVertexSetTextureMatrixEnable(JNIEnv *_env, jobject _this, jboolean enable) 807{ 808 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 809 LOG_API("nProgramVertexSetTextureMatrixEnable, con(%p), enable(%i)", con, enable); 810 rsProgramVertexSetTextureMatrixEnable(enable); 811} 812 813static void 814nProgramVertexAddLight(JNIEnv *_env, jobject _this, jint light) 815{ 816 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 817 LOG_API("nProgramVertexAddLight, con(%p), light(%p)", con, (RsLight)light); 818 rsProgramVertexAddLight((RsLight)light); 819} 820 821static jint 822nProgramVertexCreate(JNIEnv *_env, jobject _this) 823{ 824 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 825 LOG_API("nProgramVertexCreate, con(%p)", con); 826 return (jint)rsProgramVertexCreate(); 827} 828 829static void 830nProgramVertexDestroy(JNIEnv *_env, jobject _this, jint pgm) 831{ 832 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 833 LOG_API("nProgramFragmentDestroy, con(%p), pgm(%i)", con, pgm); 834 rsProgramFragmentDestroy((RsProgramFragment)pgm); 835} 836 837 838 839 840// --------------------------------------------------------------------------- 841 842static void 843nContextBindRootScript(JNIEnv *_env, jobject _this, jint script) 844{ 845 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 846 LOG_API("nContextBindRootScript, con(%p), script(%p)", con, (RsScript)script); 847 rsContextBindRootScript((RsScript)script); 848} 849 850static void 851nContextBindProgramFragmentStore(JNIEnv *_env, jobject _this, jint pfs) 852{ 853 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 854 LOG_API("nContextBindProgramFragmentStore, con(%p), pfs(%p)", con, (RsProgramFragmentStore)pfs); 855 rsContextBindProgramFragmentStore((RsProgramFragmentStore)pfs); 856} 857 858static void 859nContextBindProgramFragment(JNIEnv *_env, jobject _this, jint pf) 860{ 861 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 862 LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", con, (RsProgramFragment)pf); 863 rsContextBindProgramFragment((RsProgramFragment)pf); 864} 865 866static void 867nContextBindProgramVertex(JNIEnv *_env, jobject _this, jint pf) 868{ 869 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 870 LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", con, (RsProgramVertex)pf); 871 rsContextBindProgramVertex((RsProgramVertex)pf); 872} 873 874// --------------------------------------------------------------------------- 875 876static void 877nSamplerDestroy(JNIEnv *_env, jobject _this, jint s) 878{ 879 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 880 LOG_API("nSamplerDestroy, con(%p), sampler(%p)", con, (RsSampler)s); 881 rsSamplerDestroy((RsSampler)s); 882} 883 884static void 885nSamplerBegin(JNIEnv *_env, jobject _this) 886{ 887 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 888 LOG_API("nSamplerBegin, con(%p)", con); 889 rsSamplerBegin(); 890} 891 892static void 893nSamplerSet(JNIEnv *_env, jobject _this, jint p, jint v) 894{ 895 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 896 LOG_API("nSamplerSet, con(%p), param(%i), value(%i)", con, p, v); 897 rsSamplerSet((RsSamplerParam)p, (RsSamplerValue)v); 898} 899 900static jint 901nSamplerCreate(JNIEnv *_env, jobject _this) 902{ 903 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 904 LOG_API("nSamplerCreate, con(%p)", con); 905 return (jint)rsSamplerCreate(); 906} 907 908// --------------------------------------------------------------------------- 909 910static void 911nLightBegin(JNIEnv *_env, jobject _this) 912{ 913 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 914 LOG_API("nLightBegin, con(%p)", con); 915 rsLightBegin(); 916} 917 918static void 919nLightSetIsMono(JNIEnv *_env, jobject _this, jboolean isMono) 920{ 921 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 922 LOG_API("nLightSetIsMono, con(%p), isMono(%i)", con, isMono); 923 rsLightSetMonochromatic(isMono); 924} 925 926static void 927nLightSetIsLocal(JNIEnv *_env, jobject _this, jboolean isLocal) 928{ 929 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 930 LOG_API("nLightSetIsLocal, con(%p), isLocal(%i)", con, isLocal); 931 rsLightSetLocal(isLocal); 932} 933 934static jint 935nLightCreate(JNIEnv *_env, jobject _this) 936{ 937 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 938 LOG_API("nLightCreate, con(%p)", con); 939 return (jint)rsLightCreate(); 940} 941 942static void 943nLightDestroy(JNIEnv *_env, jobject _this, jint light) 944{ 945 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 946 LOG_API("nLightDestroy, con(%p), light(%p)", con, (RsLight)light); 947 rsLightDestroy((RsLight)light); 948} 949 950static void 951nLightSetColor(JNIEnv *_env, jobject _this, jint light, float r, float g, float b) 952{ 953 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 954 LOG_API("nLightSetColor, con(%p), light(%p), r(%f), g(%f), b(%f)", con, (RsLight)light, r, g, b); 955 rsLightSetColor((RsLight)light, r, g, b); 956} 957 958static void 959nLightSetPosition(JNIEnv *_env, jobject _this, jint light, float x, float y, float z) 960{ 961 RsContext con = (RsContext)(_env->GetIntField(_this, gContextId)); 962 LOG_API("nLightSetPosition, con(%p), light(%p), x(%f), y(%f), z(%f)", con, (RsLight)light, x, y, z); 963 rsLightSetPosition((RsLight)light, x, y, z); 964} 965 966// --------------------------------------------------------------------------- 967 968 969static const char *classPathName = "android/renderscript/RenderScript"; 970 971static JNINativeMethod methods[] = { 972{"_nInit", "()V", (void*)_nInit }, 973{"nDeviceCreate", "()I", (void*)nDeviceCreate }, 974{"nDeviceDestroy", "(I)V", (void*)nDeviceDestroy }, 975{"nContextCreate", "(ILandroid/view/Surface;I)I", (void*)nContextCreate }, 976{"nContextDestroy", "(I)V", (void*)nContextDestroy }, 977{"nAssignName", "(I[B)V", (void*)nAssignName }, 978 979{"nFileOpen", "([B)I", (void*)nFileOpen }, 980 981{"nElementBegin", "()V", (void*)nElementBegin }, 982{"nElementAddPredefined", "(I)V", (void*)nElementAddPredefined }, 983{"nElementAdd", "(IIII)V", (void*)nElementAdd }, 984{"nElementCreate", "()I", (void*)nElementCreate }, 985{"nElementGetPredefined", "(I)I", (void*)nElementGetPredefined }, 986{"nElementDestroy", "(I)V", (void*)nElementDestroy }, 987 988{"nTypeBegin", "(I)V", (void*)nTypeBegin }, 989{"nTypeAdd", "(II)V", (void*)nTypeAdd }, 990{"nTypeCreate", "()I", (void*)nTypeCreate }, 991{"nTypeDestroy", "(I)V", (void*)nTypeDestroy }, 992 993{"nAllocationCreateTyped", "(I)I", (void*)nAllocationCreateTyped }, 994{"nAllocationCreatePredefSized", "(II)I", (void*)nAllocationCreatePredefSized }, 995{"nAllocationCreateSized", "(II)I", (void*)nAllocationCreateSized }, 996{"nAllocationCreateFromBitmap", "(IZLandroid/graphics/Bitmap;)I", (void*)nAllocationCreateFromBitmap }, 997{"nAllocationUploadToTexture", "(II)V", (void*)nAllocationUploadToTexture }, 998{"nAllocationDestroy", "(I)V", (void*)nAllocationDestroy }, 999{"nAllocationData", "(I[I)V", (void*)nAllocationData_i }, 1000{"nAllocationData", "(I[F)V", (void*)nAllocationData_f }, 1001{"nAllocationSubData1D", "(III[I)V", (void*)nAllocationSubData1D_i }, 1002{"nAllocationSubData1D", "(III[F)V", (void*)nAllocationSubData1D_f }, 1003{"nAllocationSubData2D", "(IIIII[I)V", (void*)nAllocationSubData2D_i }, 1004{"nAllocationSubData2D", "(IIIII[F)V", (void*)nAllocationSubData2D_f }, 1005 1006{"nTriangleMeshDestroy", "(I)V", (void*)nTriangleMeshDestroy }, 1007{"nTriangleMeshBegin", "(II)V", (void*)nTriangleMeshBegin }, 1008{"nTriangleMeshAddVertex_XY", "(FF)V", (void*)nTriangleMeshAddVertex_XY }, 1009{"nTriangleMeshAddVertex_XYZ", "(FFF)V", (void*)nTriangleMeshAddVertex_XYZ }, 1010{"nTriangleMeshAddVertex_XY_ST", "(FFFF)V", (void*)nTriangleMeshAddVertex_XY_ST }, 1011{"nTriangleMeshAddVertex_XYZ_ST", "(FFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST }, 1012{"nTriangleMeshAddVertex_XYZ_ST_NORM", "(FFFFFFFF)V", (void*)nTriangleMeshAddVertex_XYZ_ST_NORM }, 1013{"nTriangleMeshAddTriangle", "(III)V", (void*)nTriangleMeshAddTriangle }, 1014{"nTriangleMeshCreate", "()I", (void*)nTriangleMeshCreate }, 1015 1016{"nAdapter1DDestroy", "(I)V", (void*)nAdapter1DDestroy }, 1017{"nAdapter1DBindAllocation", "(II)V", (void*)nAdapter1DBindAllocation }, 1018{"nAdapter1DSetConstraint", "(III)V", (void*)nAdapter1DSetConstraint }, 1019{"nAdapter1DData", "(I[I)V", (void*)nAdapter1DData_i }, 1020{"nAdapter1DSubData", "(III[I)V", (void*)nAdapter1DSubData_i }, 1021{"nAdapter1DData", "(I[F)V", (void*)nAdapter1DData_f }, 1022{"nAdapter1DSubData", "(III[F)V", (void*)nAdapter1DSubData_f }, 1023{"nAdapter1DCreate", "()I", (void*)nAdapter1DCreate }, 1024 1025{"nScriptDestroy", "(I)V", (void*)nScriptDestroy }, 1026{"nScriptBindAllocation", "(III)V", (void*)nScriptBindAllocation }, 1027{"nScriptCBegin", "()V", (void*)nScriptCBegin }, 1028{"nScriptCSetClearColor", "(FFFF)V", (void*)nScriptCSetClearColor }, 1029{"nScriptCSetClearDepth", "(F)V", (void*)nScriptCSetClearDepth }, 1030{"nScriptCSetClearStencil", "(I)V", (void*)nScriptCSetClearStencil }, 1031{"nScriptCAddType", "(I)V", (void*)nScriptCAddType }, 1032{"nScriptCSetRoot", "(Z)V", (void*)nScriptCSetRoot }, 1033{"nScriptCSetScript", "([BII)V", (void*)nScriptCSetScript }, 1034{"nScriptCCreate", "()I", (void*)nScriptCCreate }, 1035 1036{"nProgramFragmentStoreBegin", "(II)V", (void*)nProgramFragmentStoreBegin }, 1037{"nProgramFragmentStoreDepthFunc", "(I)V", (void*)nProgramFragmentStoreDepthFunc }, 1038{"nProgramFragmentStoreDepthMask", "(Z)V", (void*)nProgramFragmentStoreDepthMask }, 1039{"nProgramFragmentStoreColorMask", "(ZZZZ)V", (void*)nProgramFragmentStoreColorMask }, 1040{"nProgramFragmentStoreBlendFunc", "(II)V", (void*)nProgramFragmentStoreBlendFunc }, 1041{"nProgramFragmentStoreDither", "(Z)V", (void*)nProgramFragmentStoreDither }, 1042{"nProgramFragmentStoreCreate", "()I", (void*)nProgramFragmentStoreCreate }, 1043{"nProgramFragmentStoreDestroy", "(I)V", (void*)nProgramFragmentStoreDestroy }, 1044 1045{"nProgramFragmentBegin", "(II)V", (void*)nProgramFragmentBegin }, 1046{"nProgramFragmentBindTexture", "(III)V", (void*)nProgramFragmentBindTexture }, 1047{"nProgramFragmentBindSampler", "(III)V", (void*)nProgramFragmentBindSampler }, 1048{"nProgramFragmentSetType", "(II)V", (void*)nProgramFragmentSetType }, 1049{"nProgramFragmentSetEnvMode", "(II)V", (void*)nProgramFragmentSetEnvMode }, 1050{"nProgramFragmentSetTexEnable", "(IZ)V", (void*)nProgramFragmentSetTexEnable }, 1051{"nProgramFragmentCreate", "()I", (void*)nProgramFragmentCreate }, 1052{"nProgramFragmentDestroy", "(I)V", (void*)nProgramFragmentDestroy }, 1053 1054{"nProgramVertexDestroy", "(I)V", (void*)nProgramVertexDestroy }, 1055{"nProgramVertexBindAllocation", "(III)V", (void*)nProgramVertexBindAllocation }, 1056{"nProgramVertexBegin", "(II)V", (void*)nProgramVertexBegin }, 1057{"nProgramVertexSetType", "(II)V", (void*)nProgramVertexSetType }, 1058{"nProgramVertexSetTextureMatrixEnable", "(Z)V", (void*)nProgramVertexSetTextureMatrixEnable }, 1059{"nProgramVertexAddLight", "(I)V", (void*)nProgramVertexAddLight }, 1060{"nProgramVertexCreate", "()I", (void*)nProgramVertexCreate }, 1061 1062{"nLightBegin", "()V", (void*)nLightBegin }, 1063{"nLightSetIsMono", "(Z)V", (void*)nLightSetIsMono }, 1064{"nLightSetIsLocal", "(Z)V", (void*)nLightSetIsLocal }, 1065{"nLightCreate", "()I", (void*)nLightCreate }, 1066{"nLightDestroy", "(I)V", (void*)nLightDestroy }, 1067{"nLightSetColor", "(IFFF)V", (void*)nLightSetColor }, 1068{"nLightSetPosition", "(IFFF)V", (void*)nLightSetPosition }, 1069 1070{"nContextBindRootScript", "(I)V", (void*)nContextBindRootScript }, 1071{"nContextBindProgramFragmentStore","(I)V", (void*)nContextBindProgramFragmentStore }, 1072{"nContextBindProgramFragment", "(I)V", (void*)nContextBindProgramFragment }, 1073{"nContextBindProgramVertex", "(I)V", (void*)nContextBindProgramVertex }, 1074 1075{"nSamplerDestroy", "(I)V", (void*)nSamplerDestroy }, 1076{"nSamplerBegin", "()V", (void*)nSamplerBegin }, 1077{"nSamplerSet", "(II)V", (void*)nSamplerSet }, 1078{"nSamplerCreate", "()I", (void*)nSamplerCreate }, 1079 1080}; 1081 1082static int registerFuncs(JNIEnv *_env) 1083{ 1084 return android::AndroidRuntime::registerNativeMethods( 1085 _env, classPathName, methods, NELEM(methods)); 1086} 1087 1088// --------------------------------------------------------------------------- 1089 1090jint JNI_OnLoad(JavaVM* vm, void* reserved) 1091{ 1092 JNIEnv* env = NULL; 1093 jint result = -1; 1094 1095 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { 1096 LOGE("ERROR: GetEnv failed\n"); 1097 goto bail; 1098 } 1099 assert(env != NULL); 1100 1101 if (registerFuncs(env) < 0) { 1102 LOGE("ERROR: MediaPlayer native registration failed\n"); 1103 goto bail; 1104 } 1105 1106 /* success -- return valid version number */ 1107 result = JNI_VERSION_1_4; 1108 1109bail: 1110 return result; 1111} 1112