2009-03-04 03:31:44 +00:00
|
|
|
**
|
2009-04-16 02:13:17 +00:00
|
|
|
** Copyright 2009, The Android Open Source Project
|
2009-03-04 03:31:44 +00:00
|
|
|
**
|
2011-04-09 03:01:01 +00:00
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
2009-03-04 03:31:44 +00:00
|
|
|
**
|
2011-04-09 03:01:01 +00:00
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
2009-03-04 03:31:44 +00:00
|
|
|
**
|
2011-04-09 03:01:01 +00:00
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
2009-03-04 03:31:44 +00:00
|
|
|
** limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This source file is automatically generated
|
|
|
|
|
2011-04-09 03:01:01 +00:00
|
|
|
#include "jni.h"
|
|
|
|
#include "JNIHelp.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <android_runtime/AndroidRuntime.h>
|
|
|
|
#include <utils/misc.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <GLES/gl.h>
|
2009-05-07 16:52:14 +00:00
|
|
|
#include <GLES/glext.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2009-12-08 07:43:51 +00:00
|
|
|
/* special calls implemented in Android's GLES wrapper used to more
|
|
|
|
* efficiently bound-check passed arrays */
|
|
|
|
extern "C" {
|
|
|
|
GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, GLsizei stride,
|
|
|
|
const GLvoid *ptr, GLsizei count);
|
|
|
|
GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, GLsizei stride,
|
|
|
|
const GLvoid *ptr, GLsizei count);
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
static int initialized = 0;
|
|
|
|
|
|
|
|
static jclass nioAccessClass;
|
|
|
|
static jclass bufferClass;
|
|
|
|
static jmethodID getBasePointerID;
|
|
|
|
static jmethodID getBaseArrayID;
|
|
|
|
static jmethodID getBaseArrayOffsetID;
|
|
|
|
static jfieldID positionID;
|
|
|
|
static jfieldID limitID;
|
|
|
|
static jfieldID elementSizeShiftID;
|
|
|
|
|
|
|
|
/* Cache method IDs each time the class is loaded. */
|
|
|
|
|
2009-04-16 02:13:17 +00:00
|
|
|
static void
|
2011-04-09 03:01:01 +00:00
|
|
|
nativeClassInit(JNIEnv *_env, jclass glImplClass)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess");
|
|
|
|
nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal);
|
|
|
|
|
|
|
|
jclass bufferClassLocal = _env->FindClass("java/nio/Buffer");
|
|
|
|
bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal);
|
|
|
|
|
|
|
|
getBasePointerID = _env->GetStaticMethodID(nioAccessClass,
|
|
|
|
"getBasePointer", "(Ljava/nio/Buffer;)J");
|
|
|
|
getBaseArrayID = _env->GetStaticMethodID(nioAccessClass,
|
|
|
|
"getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;");
|
|
|
|
getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass,
|
|
|
|
"getBaseArrayOffset", "(Ljava/nio/Buffer;)I");
|
|
|
|
|
|
|
|
positionID = _env->GetFieldID(bufferClass, "position", "I");
|
|
|
|
limitID = _env->GetFieldID(bufferClass, "limit", "I");
|
|
|
|
elementSizeShiftID =
|
|
|
|
_env->GetFieldID(bufferClass, "_elementSizeShift", "I");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void *
|
2012-07-12 18:16:20 +00:00
|
|
|
getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *offset)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
jint position;
|
|
|
|
jint limit;
|
|
|
|
jint elementSizeShift;
|
|
|
|
jlong pointer;
|
|
|
|
|
|
|
|
position = _env->GetIntField(buffer, positionID);
|
|
|
|
limit = _env->GetIntField(buffer, limitID);
|
|
|
|
elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
|
|
|
|
*remaining = (limit - position) << elementSizeShift;
|
|
|
|
pointer = _env->CallStaticLongMethod(nioAccessClass,
|
|
|
|
getBasePointerID, buffer);
|
|
|
|
if (pointer != 0L) {
|
|
|
|
*array = NULL;
|
|
|
|
return (void *) (jint) pointer;
|
|
|
|
}
|
2011-04-09 03:01:01 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
*array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
|
|
|
|
getBaseArrayID, buffer);
|
2012-07-12 18:16:20 +00:00
|
|
|
*offset = _env->CallStaticIntMethod(nioAccessClass,
|
2009-03-04 03:31:44 +00:00
|
|
|
getBaseArrayOffsetID, buffer);
|
2012-07-12 18:16:20 +00:00
|
|
|
return NULL;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
releasePointer(JNIEnv *_env, jarray array, void *data, jboolean commit)
|
|
|
|
{
|
|
|
|
_env->ReleasePrimitiveArrayCritical(array, data,
|
|
|
|
commit ? 0 : JNI_ABORT);
|
|
|
|
}
|
|
|
|
|
2009-12-08 07:43:51 +00:00
|
|
|
static void *
|
|
|
|
getDirectBufferPointer(JNIEnv *_env, jobject buffer) {
|
|
|
|
char* buf = (char*) _env->GetDirectBufferAddress(buffer);
|
|
|
|
if (buf) {
|
|
|
|
jint position = _env->GetIntField(buffer, positionID);
|
|
|
|
jint elementSizeShift = _env->GetIntField(buffer, elementSizeShiftID);
|
|
|
|
buf += position << elementSizeShift;
|
|
|
|
} else {
|
2011-04-09 03:01:01 +00:00
|
|
|
jniThrowException(_env, "java/lang/IllegalArgumentException",
|
|
|
|
"Must use a native order direct Buffer");
|
2009-12-08 07:43:51 +00:00
|
|
|
}
|
|
|
|
return (void*) buf;
|
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
// --------------------------------------------------------------------------
|