jni: new Tesselator

This commit is contained in:
Hannes Janetzek
2014-09-10 21:07:57 +02:00
parent 59ab24da90
commit 7db70f239f
32 changed files with 4194 additions and 421 deletions

22
jni/jni/Android.mk Normal file
View File

@@ -0,0 +1,22 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := vtm-jni
LOCAL_C_INCLUDES := . libtess2/Include
LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O2 -Wall -D__ANDROID__ -Wall -std=c99 -O2 -ffast-math -DNDEBUG
LOCAL_CPPFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O2 -Wall -D__ANDROID__ -Wall -std=c99 -O2 -ffast-math -DNDEBUG
LOCAL_LDLIBS := -lm -llog
LOCAL_ARM_MODE := arm
LOCAL_SRC_FILES := libtess2/Source/sweep.c\
libtess2/Source/priorityq.c\
libtess2/Source/bucketalloc.c\
libtess2/Source/geom.c\
libtess2/Source/tess.c\
libtess2/Source/dict.c\
libtess2/Source/mesh.c\
org.oscim.utils.tess.Tesselator.cpp\
gl/utils.c
include $(BUILD_SHARED_LIBRARY)

2
jni/jni/Application.mk Normal file
View File

@@ -0,0 +1,2 @@
APP_ABI := armeabi armeabi-v7a x86
APP_PLATFORM := android-8

View File

@@ -0,0 +1,33 @@
<project name="android-natives" basedir="." default="postcompile">
<property environment="env" />
<!-- the suffix ndk-build executable -->
<property name="ndkSuffix" value="" />
<target name="clean" depends="check-for-ndk" if="has-ndk-build">
<exec executable="${env.NDK_HOME}/ndk-build${ndkSuffix}" failonerror="true">
<arg value="clean"/>
</exec>
</target>
<target name="precompile" depends="check-for-ndk">
</target>
<target name="compile-natives" depends="precompile" if="has-ndk-build">
<echo>ndk_home: ${env.NDK_HOME}</echo>
<exec executable="${env.NDK_HOME}/ndk-build${ndkSuffix}" failonerror="true"/>
</target>
<target name="postcompile" depends="compile-natives">
</target>
<target name="check-for-ndk">
<condition property="ndk-build-found">
<available file="ndk-build${ndkSuffix}" filepath="${env.NDK_HOME}"/>
</condition>
<condition property="has-ndk-build">
<equals arg1="${ndk-build-found}" arg2="true"/>
</condition>
</target>
</project>

153
jni/jni/build-linux64.xml Normal file
View File

@@ -0,0 +1,153 @@
<project name="vtm-jni-Linux-64" basedir="." default="postcompile">
<!-- include the environment -->
<property environment="env"/>
<!-- output directory for temporary object files -->
<property name="buildDir" value="target/linux64" />
<!-- output directory for the shared library -->
<property name="libsDir" value="../libs/linux64" />
<!-- the name of the shared library -->
<property name="libName" value="libvtm-jni64.so"/>
<!-- the jni header jniPlatform to use -->
<property name="jniPlatform" value="linux"/>
<!-- the compilerPrefix for the C & C++ compilers -->
<property name="compilerPrefix" value=""/>
<!-- the compilerSuffix for the C & C++ compilers -->
<property name="compilerSuffix" value="" />
<!-- define gcc compiler, options and files to compile -->
<property name="gcc" value="${compilerPrefix}gcc${compilerSuffix}"/>
<property name="gcc-opts" value="-c -Wall -O2 -mfpmath=sse -msse -fmessage-length=0 -m64 -fPIC -Wall -std=c99 -O2 -ffast-math -DNDEBUG"/>
<fileset id="gcc-files" dir="./">
<exclude name="target/"/>
<include name="memcpy_wrap.c"/>
<include name="gl/utils.c"/>
<include name="libtess2/Source/bucketalloc.c"/>
<include name="libtess2/Source/dict.c"/>
<include name="libtess2/Source/geom.c"/>
<include name="libtess2/Source/mesh.c"/>
<include name="libtess2/Source/priorityq.c"/>
<include name="libtess2/Source/sweep.c"/>
<include name="libtess2/Source/tess.c"/>
</fileset>
<!-- define g++ compiler, options and files to compile -->
<property name="g++" value="${compilerPrefix}g++${compilerSuffix}"/>
<property name="g++-opts" value="-c -Wall -O2 -mfpmath=sse -msse -fmessage-length=0 -m64 -fPIC -Wall -std=c99 -O2 -ffast-math -DNDEBUG"/>
<fileset id="g++-files" dir="./">
<exclude name="target/"/>
<include name="**/*.cpp"/>
</fileset>
<!-- define linker and options -->
<property name="linker" value="${compilerPrefix}g++${compilerSuffix}"/>
<property name="linker-opts" value="-shared -m64 -Wl,-wrap,memcpy"/>
<property name="libraries" value=""/>
<!-- cleans the build directory, removes all object files and shared libs -->
<target name="clean">
<delete includeemptydirs="true" quiet="true">
<fileset dir="${buildDir}"/>
<fileset dir="${libsDir}" includes="**/*" excludes="**/.svn"/>
</delete>
</target>
<target name="precompile">
<condition property="compiler-found">
<and>
<or>
<!-- Include both b/c Windows might be either -->
<available file="${g++}" filepath="${env.PATH}"/>
<available file="${g++}" filepath="${env.Path}"/>
</or>
<or>
<!-- Include both b/c Windows might be either -->
<available file="${gcc}" filepath="${env.PATH}"/>
<available file="${gcc}" filepath="${env.Path}"/>
</or>
</and>
</condition>
<condition property="has-compiler">
<equals arg1="${compiler-found}" arg2="true"/>
</condition>
</target>
<target name="create-build-dir" depends="precompile" if="has-compiler">
<!-- FIXME this is pretty nasty :/ -->
<copy todir="${buildDir}">
<fileset refid="g++-files"/>
<fileset refid="gcc-files"/>
</copy>
<delete>
<fileset dir="${buildDir}">
<include name="*"/>
<exclude name="*.o"/>
</fileset>
</delete>
</target>
<!-- compiles all C and C++ files to object files in the build directory -->
<target name="compile" depends="create-build-dir" if="has-compiler">
<mkdir dir="${buildDir}"/>
<apply failonerror="true" executable="${g++}" dest="${buildDir}" verbose="true">
<arg line="${g++-opts}"/>
<arg value="-Ijni-headers"/>
<arg value="-Ijni-headers/${jniPlatform}"/>
<arg value="-I."/>
<arg value="-I."/>
<arg value="-Ilibtess2/Include"/>
<srcfile/>
<arg value="-o"/>
<targetfile/>
<fileset refid="g++-files"/>
<compositemapper>
<mapper type="glob" from="*.cpp" to="*.o"/>
<mapper type="glob" from="*.mm" to="*.o"/>
</compositemapper>
</apply>
<apply failonerror="true" executable="${gcc}" dest="${buildDir}" verbose="true">
<arg line="${gcc-opts}"/>
<arg value="-Ijni-headers"/>
<arg value="-Ijni-headers/${jniPlatform}"/>
<arg value="-I."/>
<arg value="-I."/>
<arg value="-Ilibtess2/Include"/>
<srcfile/>
<arg value="-o"/>
<targetfile/>
<fileset refid="gcc-files"/>
<compositemapper>
<mapper type="glob" from="*.c" to="*.o"/>
<mapper type="glob" from="*.m" to="*.o"/>
</compositemapper>
</apply>
</target>
<!-- links the shared library based on the previously compiled object files -->
<target name="link" depends="compile" if="has-compiler">
<fileset dir="${buildDir}" id="objFileSet">
<patternset>
<include name="**/*.o" />
</patternset>
</fileset>
<pathconvert pathsep=" " property="objFiles" refid="objFileSet" />
<mkdir dir="${libsDir}" />
<exec executable="${linker}" failonerror="true" dir="${buildDir}">
<arg line="${linker-opts}" />
<arg value="-o" />
<arg path="${libsDir}/${libName}" />
<arg line="${objFiles}"/>
<arg line="${libraries}" />
</exec>
</target>
<target name="postcompile" depends="link">
</target>
</project>

32
jni/jni/build.xml Normal file
View File

@@ -0,0 +1,32 @@
<project name="vtm-jni-natives" basedir="." default="all">
<target name="clean">
<ant antfile="build-android32.xml" target="clean"/>
<ant antfile="build-linux64.xml" target="clean"/>
<ant antfile="build-linux32.xml" target="clean"/>
<ant antfile="build-windows32.xml" target="clean"/>
<ant antfile="build-windows64.xml" target="clean"/>
</target>
<target name="compile-natives">
<ant antfile="build-android32.xml"/>
<ant antfile="build-linux64.xml"/>
<ant antfile="build-linux32.xml"/>
<ant antfile="build-windows32.xml"/>
<ant antfile="build-windows64.xml"/>
</target>
<target name="pack-natives">
<jar destfile="../libs/vtm-jni-natives.jar">
<fileset dir="../libs/linux64" includes="libvtm-jni64.so"/>
<fileset dir="../libs/linux32" includes="libvtm-jni.so"/>
<fileset dir="../libs/macosx32" includes="libvtm-jni.so"/>
<fileset dir="../libs/windows32" includes="libvtm-jni.dylib"/>
<fileset dir="../libs/windows64" includes="libvtm-jni.a"/>
</jar>
</target>
<target name="all" depends="compile-natives,pack-natives"/>
</project>

550
jni/jni/gl/utils.c Normal file
View File

@@ -0,0 +1,550 @@
#include <jni.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#ifndef __WIN32__
#include <alloca.h>
//#else
//#define alloca(size) __builtin_alloca(size)
#endif
//#ifndef uintptr_t
//typedef unsigned long uintptr_t;
//#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#if 0
#ifdef __ANDROID__
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <android/log.h>
#define JNI(X) JNIEXPORT Java_org_oscim_utils_GlUtils_##X
#define COLOR_R(C) (((C >> 16) & 0xff) / 255.0f)
#define COLOR_G(C) (((C >> 8) & 0xff) / 255.0f)
#define COLOR_B(C) (((C >> 0) & 0xff) / 255.0f)
#define COLOR_A(C) (((C >> 24) & 0xff) / 255.0f)
void JNI(setColor)(JNIEnv *env, jclass* clazz, jint location, jint c, jfloat alpha)
{
if (alpha >= 1)
alpha = COLOR_A(c);
else if (alpha < 0)
alpha = 0;
else
alpha *= COLOR_A(c);
if (alpha == 1)
{
glUniform4f((GLint) location,
(GLfloat) COLOR_R(c),
(GLfloat) COLOR_G(c),
(GLfloat) COLOR_B(c),
(GLfloat) alpha);
}
else
{
glUniform4f((GLint) location,
(GLfloat) (COLOR_R(c) * alpha),
(GLfloat) (COLOR_G(c) * alpha),
(GLfloat) (COLOR_B(c) * alpha),
(GLfloat) alpha);
}
}
void JNI(setColorBlend)(JNIEnv *env, jclass* clazz, jint location, jint c1, jint c2, jfloat mix)
{
float a1 = COLOR_A(c1) * (1 - mix);
float a2 = COLOR_A(c2) * mix;
glUniform4f((GLint) location,
(GLfloat) (COLOR_R(c1) * a1 + COLOR_R(c2) * a2),
(GLfloat) (COLOR_G(c1) * a1 + COLOR_G(c2) * a2),
(GLfloat) (COLOR_B(c1) * a1 + COLOR_B(c2) * a2),
(GLfloat) (a1 + a2));
}
#endif // __ANDROID__
#endif // 0
#undef JNI
#define JNI(X) JNIEXPORT Java_org_oscim_renderer_GLMatrix_##X
#define CAST(x) (float *)(uintptr_t) x
#define MAT_SIZE 16 * sizeof(float)
static const float identity[] =
{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
static inline void
multiplyMM(float* r, const float* lhs, const float* rhs);
static inline void
setRotateM(float* rm, int rmOffset, float a, float x, float y, float z);
static inline void
transposeM(float* mTrans, int mTransOffset, float* m, int mOffset);
static inline void
matrix4_proj(float* mat, float* vec);
static inline void
matrix4_proj2D(float* mat, float* vec, float *out);
jlong JNI(alloc)(JNIEnv *env, jclass* clazz)
{
return (long) calloc(16, sizeof(float));
}
jobject JNI(getBuffer)(JNIEnv *env, jclass* clazz,jlong ptr){
return (*env)->NewDirectByteBuffer(env,(char*)(uintptr_t)ptr, 16*sizeof(float));
}
void JNI(delete)(JNIEnv* env, jclass* clazz, jlong ptr)
{
free(CAST(ptr));
}
#if 0
void JNI(setAsUniform)(JNIEnv* env, jclass* clazz, jlong ptr, jint location)
{
float* m = CAST(ptr);
glUniformMatrix4fv((GLint) location, (GLsizei) 1, (GLboolean) 0, (GLfloat *) m);
}
#endif
void JNI(setValueAt)(JNIEnv* env, jclass* clazz, jlong ptr, jint pos, jfloat value)
{
float* m = CAST(ptr);
if (pos > -1 && pos < 16)
m[pos] = value;
}
void JNI(identity)(JNIEnv* env, jclass* clazz, jlong ptr)
{
float* m = CAST(ptr);
memcpy(m, identity, MAT_SIZE);
}
void JNI(setScale)(JNIEnv* env, jclass* clazz, jlong ptr, jfloat sx, jfloat sy, jfloat sz)
{
float* m = CAST(ptr);
memcpy(m, identity, MAT_SIZE);
m[0] = sx;
m[5] = sy;
m[10] = sz;
}
void JNI(setTranslation)(JNIEnv* env, jclass* clazz, jlong ptr, jfloat x, jfloat y, jfloat z)
{
float* m = CAST(ptr);
memcpy(m, identity, MAT_SIZE);
m[12] = x;
m[13] = y;
m[14] = z;
}
void JNI(setRotation)(JNIEnv* env, jclass* clazz, jlong ptr, jfloat a, jfloat x, jfloat y, jfloat z)
{
float* m = CAST(ptr);
setRotateM(m, 0, a, x, y, z);
}
void JNI(setTransScale)(JNIEnv* env, jclass* clazz, jlong ptr, jfloat tx, jfloat ty, jfloat scale)
{
float* m = CAST(ptr);
memcpy(m, identity, MAT_SIZE);
m[0] = scale;
m[5] = scale;
m[12] = tx;
m[13] = ty;
}
// set matrix from float array
void JNI(set)(JNIEnv* env, jclass* clazz, jlong ptr, jfloatArray obj_mat)
{
float* m = CAST(ptr);
float* mat = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_mat, 0);
memcpy(m, mat, MAT_SIZE);
(*env)->ReleasePrimitiveArrayCritical(env, obj_mat, mat, JNI_ABORT);
}
// get float array from matrix
void JNI(get)(JNIEnv* env, jclass* clazz, jlong ptr, jfloatArray obj_mat)
{
float* m = CAST(ptr);
float* mat = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_mat, 0);
memcpy(mat, m, MAT_SIZE);
(*env)->ReleasePrimitiveArrayCritical(env, obj_mat, mat, 0);
}
void JNI(mul)(JNIEnv* env, jclass* clazz, jlong ptr_a, jlong ptr_b)
{
float* mata = CAST(ptr_a);
float* matb = CAST(ptr_b);
multiplyMM(mata, mata, matb);
}
void JNI(copy)(JNIEnv* env, jclass* clazz, jlong ptr_dst, jlong ptr_src)
{
float* dst = CAST(ptr_dst);
float* src = CAST(ptr_src);
memcpy(dst, src, MAT_SIZE);
}
void JNI(smul)(JNIEnv* env, jclass* clazz, jlong ptr_r, jlong ptr_a, jlong ptr_b)
{
float* matr = CAST(ptr_r);
float* mata = CAST(ptr_a);
float* matb = CAST(ptr_b);
multiplyMM(matr, mata, matb);
}
void JNI(smulrhs)(JNIEnv* env, jclass* clazz, jlong ptr_r, jlong ptr_rhs)
{
float* matr = CAST(ptr_r);
float* mata = alloca(16 * sizeof(float));
float* matb = CAST(ptr_rhs);
memcpy(mata, matr, 16 * sizeof(float));
multiplyMM(matr, mata, matb);
}
void JNI(smullhs)(JNIEnv* env, jclass* clazz, jlong ptr_r, jlong ptr_lhs)
{
float* matr = CAST(ptr_r);
float* mata = CAST(ptr_lhs);
float* matb = alloca(16 * sizeof(float));
memcpy(matb, matr, 16 * sizeof(float));
multiplyMM(matr, mata, matb);
}
void JNI(strans)(JNIEnv* env, jclass* clazz, jlong ptr_r, jlong ptr_a)
{
float* matr = CAST(ptr_r);
float* mata = CAST(ptr_a);
transposeM(matr, 0, mata, 0);
}
void JNI(prj)(JNIEnv* env, jclass* clazz, jlong ptr, jfloatArray obj_vec){
float* m = CAST(ptr);
float* vec = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_vec, 0);
matrix4_proj(m, vec);
(*env)->ReleasePrimitiveArrayCritical(env, obj_vec, vec, 0);
}
void JNI(prj3D)(JNIEnv* env, jclass* clazz, jlong ptr, jfloatArray obj_vec, int offset, int cnt)
{
float* m = CAST(ptr);
float* vec = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_vec, 0);
int length = cnt * 3;
for (int i = offset * 3; i < length; i += 3)
matrix4_proj(m, (vec + i));
(*env)->ReleasePrimitiveArrayCritical(env, obj_vec, vec, 0);
}
void JNI(prj2D)(JNIEnv* env, jclass* clazz, jlong ptr, jfloatArray obj_vec, int offset, int cnt)
{
float* m = CAST(ptr);
float* vec = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_vec, 0);
offset *= 2;
for (int end = offset + cnt * 2; offset < end; offset += 2)
matrix4_proj2D(m, (vec + offset), (vec + offset));
(*env)->ReleasePrimitiveArrayCritical(env, obj_vec, vec, 0);
}
void JNI(prj2D2)(JNIEnv* env, jclass* clazz, jlong ptr,
jfloatArray obj_src_vec, int src_offset,
jfloatArray obj_dst_vec, int dst_offset, int cnt)
{
float* m = CAST(ptr);
float* src = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_src_vec, 0);
float* dst = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_dst_vec, 0);
int off_src = src_offset * 2;
int off_dst = dst_offset * 2;
for (int end = off_src + cnt * 2; off_src < end; off_src += 2, off_dst += 2)
matrix4_proj2D(m, (src + off_src), (dst + off_dst));
(*env)->ReleasePrimitiveArrayCritical(env, obj_dst_vec, dst, 0);
(*env)->ReleasePrimitiveArrayCritical(env, obj_src_vec, src, 0);
}
static float someRandomEpsilon = 1.0f / (1 << 11);
void JNI(addDepthOffset)(JNIEnv* env, jclass* clazz, jlong ptr, jint delta)
{
float* m = CAST(ptr);
// from http://www.mathfor3dgameprogramming.com/code/Listing9.1.cpp
// float n = MapViewPosition.VIEW_NEAR;
// float f = MapViewPosition.VIEW_FAR;
// float pz = 1;
// float epsilon = -2.0f * f * n * delta / ((f + n) * pz * (pz + delta));
m[10] *= 1.0f + someRandomEpsilon * delta;
}
/*
* Copyright 2007, The Android Open Source Project
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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
* limitations under the License.
*/
// from android/platform_frameworks_base/blob/master/core/jni/android/opengl/util.cpp
#define I(_i, _j) ((_j)+ 4*(_i))
static inline void
multiplyMM(float* r, const float* lhs, const float* rhs)
{
for (int i = 0; i < 4; i++)
{
register const float rhs_i0 = rhs[I(i,0)];
register float ri0 = lhs[I(0,0)] * rhs_i0;
register float ri1 = lhs[I(0,1)] * rhs_i0;
register float ri2 = lhs[I(0,2)] * rhs_i0;
register float ri3 = lhs[I(0,3)] * rhs_i0;
for (int j = 1; j < 4; j++)
{
register const float rhs_ij = rhs[I(i,j)];
ri0 += lhs[I(j,0)] * rhs_ij;
ri1 += lhs[I(j,1)] * rhs_ij;
ri2 += lhs[I(j,2)] * rhs_ij;
ri3 += lhs[I(j,3)] * rhs_ij;
}
r[I(i,0)] = ri0;
r[I(i,1)] = ri1;
r[I(i,2)] = ri2;
r[I(i,3)] = ri3;
}
}
//static inline
//void
//mx4transform(float x, float y, float z, float w, const float* pM, float* pDest)
//{
// pDest[0] = pM[0 + 4 * 0] * x + pM[0 + 4 * 1] * y + pM[0 + 4 * 2] * z + pM[0 + 4 * 3] * w;
// pDest[1] = pM[1 + 4 * 0] * x + pM[1 + 4 * 1] * y + pM[1 + 4 * 2] * z + pM[1 + 4 * 3] * w;
// pDest[2] = pM[2 + 4 * 0] * x + pM[2 + 4 * 1] * y + pM[2 + 4 * 2] * z + pM[2 + 4 * 3] * w;
//
// pDest[3] = pM[3 + 4 * 0] * x + pM[3 + 4 * 1] * y + pM[3 + 4 * 2] * z + pM[3 + 4 * 3] * w;
//}
/**
* Computes the length of a vector
*
* @param x x coordinate of a vector
* @param y y coordinate of a vector
* @param z z coordinate of a vector
* @return the length of a vector
*/
static inline float
length(float x, float y, float z)
{
return (float) sqrt(x * x + y * y + z * z);
}
/**
* Rotates matrix m by angle a (in degrees) around the axis (x, y, z)
* @param rm returns the result
* @param rmOffset index into rm where the result matrix starts
* @param a angle to rotate in degrees
* @param x scale factor x
* @param y scale factor y
* @param z scale factor z
*/
static inline void
setRotateM(float* rm, int rmOffset, float a, float x, float y, float z)
{
rm[rmOffset + 3] = 0;
rm[rmOffset + 7] = 0;
rm[rmOffset + 11] = 0;
rm[rmOffset + 12] = 0;
rm[rmOffset + 13] = 0;
rm[rmOffset + 14] = 0;
rm[rmOffset + 15] = 1;
a *= (float) (M_PI / 180.0f);
float s = (float) sin(a);
float c = (float) cos(a);
if (1.0f == x && 0.0f == y && 0.0f == z)
{
rm[rmOffset + 5] = c;
rm[rmOffset + 10] = c;
rm[rmOffset + 6] = s;
rm[rmOffset + 9] = -s;
rm[rmOffset + 1] = 0;
rm[rmOffset + 2] = 0;
rm[rmOffset + 4] = 0;
rm[rmOffset + 8] = 0;
rm[rmOffset + 0] = 1;
}
else if (0.0f == x && 1.0f == y && 0.0f == z)
{
rm[rmOffset + 0] = c;
rm[rmOffset + 10] = c;
rm[rmOffset + 8] = s;
rm[rmOffset + 2] = -s;
rm[rmOffset + 1] = 0;
rm[rmOffset + 4] = 0;
rm[rmOffset + 6] = 0;
rm[rmOffset + 9] = 0;
rm[rmOffset + 5] = 1;
}
else if (0.0f == x && 0.0f == y && 1.0f == z)
{
rm[rmOffset + 0] = c;
rm[rmOffset + 5] = c;
rm[rmOffset + 1] = s;
rm[rmOffset + 4] = -s;
rm[rmOffset + 2] = 0;
rm[rmOffset + 6] = 0;
rm[rmOffset + 8] = 0;
rm[rmOffset + 9] = 0;
rm[rmOffset + 10] = 1;
}
else
{
float len = length(x, y, z);
if (1.0f != len)
{
float recipLen = 1.0f / len;
x *= recipLen;
y *= recipLen;
z *= recipLen;
}
float nc = 1.0f - c;
float xy = x * y;
float yz = y * z;
float zx = z * x;
float xs = x * s;
float ys = y * s;
float zs = z * s;
rm[rmOffset + 0] = x * x * nc + c;
rm[rmOffset + 4] = xy * nc - zs;
rm[rmOffset + 8] = zx * nc + ys;
rm[rmOffset + 1] = xy * nc + zs;
rm[rmOffset + 5] = y * y * nc + c;
rm[rmOffset + 9] = yz * nc - xs;
rm[rmOffset + 2] = zx * nc - ys;
rm[rmOffset + 6] = yz * nc + xs;
rm[rmOffset + 10] = z * z * nc + c;
}
}
/**
* Transposes a 4 x 4 matrix.
*
* @param mTrans the array that holds the output inverted matrix
* @param mTransOffset an offset into mInv where the inverted matrix is
* stored.
* @param m the input array
* @param mOffset an offset into m where the matrix is stored.
*/
static inline void
transposeM(float* mTrans, int mTransOffset, float* m, int mOffset)
{
for (int i = 0; i < 4; i++)
{
int mBase = i * 4 + mOffset;
mTrans[i + mTransOffset] = m[mBase];
mTrans[i + 4 + mTransOffset] = m[mBase + 1];
mTrans[i + 8 + mTransOffset] = m[mBase + 2];
mTrans[i + 12 + mTransOffset] = m[mBase + 3];
}
}
/*******************************************************************************
* Copyright 2011 See libgdx AUTHORS file.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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
* limitations under the License.
******************************************************************************/
// from /gdx/src/com/badlogic/gdx/math/Matrix4.java
#define M00 0
#define M01 4
#define M02 8
#define M03 12
#define M10 1
#define M11 5
#define M12 9
#define M13 13
#define M20 2
#define M21 6
#define M22 10
#define M23 14
#define M30 3
#define M31 7
#define M32 11
#define M33 15
static inline void
matrix4_proj(float* mat, float* vec)
{
float inv_w = 1.0f / (vec[0] * mat[M30] + vec[1] * mat[M31] + vec[2] * mat[M32] + mat[M33]);
float x = (vec[0] * mat[M00] + vec[1] * mat[M01] + vec[2] * mat[M02] + mat[M03]) * inv_w;
float y = (vec[0] * mat[M10] + vec[1] * mat[M11] + vec[2] * mat[M12] + mat[M13]) * inv_w;
float z = (vec[0] * mat[M20] + vec[1] * mat[M21] + vec[2] * mat[M22] + mat[M23]) * inv_w;
vec[0] = x;
vec[1] = y;
vec[2] = z;
}
static inline void
matrix4_proj2D(float* mat, float* vec, float *out)
{
float inv_w = 1.0f / (vec[0] * mat[M30] + vec[1] * mat[M31] + mat[M33]);
float x = (vec[0] * mat[M00] + vec[1] * mat[M01] + mat[M03]) * inv_w;
float y = (vec[0] * mat[M10] + vec[1] * mat[M11] + mat[M13]) * inv_w;
out[0] = x;
out[1] = y;
}

View File

@@ -0,0 +1,523 @@
/*
* %W% %E%
*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*/
#ifndef CLASSFILE_CONSTANTS_H
#define CLASSFILE_CONSTANTS_H
#ifdef __cplusplus
extern "C" {
#endif
/* Flags */
enum {
JVM_ACC_PUBLIC = 0x0001,
JVM_ACC_PRIVATE = 0x0002,
JVM_ACC_PROTECTED = 0x0004,
JVM_ACC_STATIC = 0x0008,
JVM_ACC_FINAL = 0x0010,
JVM_ACC_SYNCHRONIZED = 0x0020,
JVM_ACC_SUPER = 0x0020,
JVM_ACC_VOLATILE = 0x0040,
JVM_ACC_BRIDGE = 0x0040,
JVM_ACC_TRANSIENT = 0x0080,
JVM_ACC_VARARGS = 0x0080,
JVM_ACC_NATIVE = 0x0100,
JVM_ACC_INTERFACE = 0x0200,
JVM_ACC_ABSTRACT = 0x0400,
JVM_ACC_STRICT = 0x0800,
JVM_ACC_SYNTHETIC = 0x1000,
JVM_ACC_ANNOTATION = 0x2000,
JVM_ACC_ENUM = 0x4000
};
/* Used in newarray instruction. */
enum {
JVM_T_BOOLEAN = 4,
JVM_T_CHAR = 5,
JVM_T_FLOAT = 6,
JVM_T_DOUBLE = 7,
JVM_T_BYTE = 8,
JVM_T_SHORT = 9,
JVM_T_INT = 10,
JVM_T_LONG = 11
};
/* Constant Pool Entries */
enum {
JVM_CONSTANT_Utf8 = 1,
JVM_CONSTANT_Unicode = 2, /* unused */
JVM_CONSTANT_Integer = 3,
JVM_CONSTANT_Float = 4,
JVM_CONSTANT_Long = 5,
JVM_CONSTANT_Double = 6,
JVM_CONSTANT_Class = 7,
JVM_CONSTANT_String = 8,
JVM_CONSTANT_Fieldref = 9,
JVM_CONSTANT_Methodref = 10,
JVM_CONSTANT_InterfaceMethodref = 11,
JVM_CONSTANT_NameAndType = 12
};
/* StackMapTable type item numbers */
enum {
JVM_ITEM_Top = 0,
JVM_ITEM_Integer = 1,
JVM_ITEM_Float = 2,
JVM_ITEM_Double = 3,
JVM_ITEM_Long = 4,
JVM_ITEM_Null = 5,
JVM_ITEM_UninitializedThis = 6,
JVM_ITEM_Object = 7,
JVM_ITEM_Uninitialized = 8
};
/* Type signatures */
enum {
JVM_SIGNATURE_ARRAY = '[',
JVM_SIGNATURE_BYTE = 'B',
JVM_SIGNATURE_CHAR = 'C',
JVM_SIGNATURE_CLASS = 'L',
JVM_SIGNATURE_ENDCLASS = ';',
JVM_SIGNATURE_ENUM = 'E',
JVM_SIGNATURE_FLOAT = 'F',
JVM_SIGNATURE_DOUBLE = 'D',
JVM_SIGNATURE_FUNC = '(',
JVM_SIGNATURE_ENDFUNC = ')',
JVM_SIGNATURE_INT = 'I',
JVM_SIGNATURE_LONG = 'J',
JVM_SIGNATURE_SHORT = 'S',
JVM_SIGNATURE_VOID = 'V',
JVM_SIGNATURE_BOOLEAN = 'Z'
};
/* Opcodes */
enum {
JVM_OPC_nop = 0,
JVM_OPC_aconst_null = 1,
JVM_OPC_iconst_m1 = 2,
JVM_OPC_iconst_0 = 3,
JVM_OPC_iconst_1 = 4,
JVM_OPC_iconst_2 = 5,
JVM_OPC_iconst_3 = 6,
JVM_OPC_iconst_4 = 7,
JVM_OPC_iconst_5 = 8,
JVM_OPC_lconst_0 = 9,
JVM_OPC_lconst_1 = 10,
JVM_OPC_fconst_0 = 11,
JVM_OPC_fconst_1 = 12,
JVM_OPC_fconst_2 = 13,
JVM_OPC_dconst_0 = 14,
JVM_OPC_dconst_1 = 15,
JVM_OPC_bipush = 16,
JVM_OPC_sipush = 17,
JVM_OPC_ldc = 18,
JVM_OPC_ldc_w = 19,
JVM_OPC_ldc2_w = 20,
JVM_OPC_iload = 21,
JVM_OPC_lload = 22,
JVM_OPC_fload = 23,
JVM_OPC_dload = 24,
JVM_OPC_aload = 25,
JVM_OPC_iload_0 = 26,
JVM_OPC_iload_1 = 27,
JVM_OPC_iload_2 = 28,
JVM_OPC_iload_3 = 29,
JVM_OPC_lload_0 = 30,
JVM_OPC_lload_1 = 31,
JVM_OPC_lload_2 = 32,
JVM_OPC_lload_3 = 33,
JVM_OPC_fload_0 = 34,
JVM_OPC_fload_1 = 35,
JVM_OPC_fload_2 = 36,
JVM_OPC_fload_3 = 37,
JVM_OPC_dload_0 = 38,
JVM_OPC_dload_1 = 39,
JVM_OPC_dload_2 = 40,
JVM_OPC_dload_3 = 41,
JVM_OPC_aload_0 = 42,
JVM_OPC_aload_1 = 43,
JVM_OPC_aload_2 = 44,
JVM_OPC_aload_3 = 45,
JVM_OPC_iaload = 46,
JVM_OPC_laload = 47,
JVM_OPC_faload = 48,
JVM_OPC_daload = 49,
JVM_OPC_aaload = 50,
JVM_OPC_baload = 51,
JVM_OPC_caload = 52,
JVM_OPC_saload = 53,
JVM_OPC_istore = 54,
JVM_OPC_lstore = 55,
JVM_OPC_fstore = 56,
JVM_OPC_dstore = 57,
JVM_OPC_astore = 58,
JVM_OPC_istore_0 = 59,
JVM_OPC_istore_1 = 60,
JVM_OPC_istore_2 = 61,
JVM_OPC_istore_3 = 62,
JVM_OPC_lstore_0 = 63,
JVM_OPC_lstore_1 = 64,
JVM_OPC_lstore_2 = 65,
JVM_OPC_lstore_3 = 66,
JVM_OPC_fstore_0 = 67,
JVM_OPC_fstore_1 = 68,
JVM_OPC_fstore_2 = 69,
JVM_OPC_fstore_3 = 70,
JVM_OPC_dstore_0 = 71,
JVM_OPC_dstore_1 = 72,
JVM_OPC_dstore_2 = 73,
JVM_OPC_dstore_3 = 74,
JVM_OPC_astore_0 = 75,
JVM_OPC_astore_1 = 76,
JVM_OPC_astore_2 = 77,
JVM_OPC_astore_3 = 78,
JVM_OPC_iastore = 79,
JVM_OPC_lastore = 80,
JVM_OPC_fastore = 81,
JVM_OPC_dastore = 82,
JVM_OPC_aastore = 83,
JVM_OPC_bastore = 84,
JVM_OPC_castore = 85,
JVM_OPC_sastore = 86,
JVM_OPC_pop = 87,
JVM_OPC_pop2 = 88,
JVM_OPC_dup = 89,
JVM_OPC_dup_x1 = 90,
JVM_OPC_dup_x2 = 91,
JVM_OPC_dup2 = 92,
JVM_OPC_dup2_x1 = 93,
JVM_OPC_dup2_x2 = 94,
JVM_OPC_swap = 95,
JVM_OPC_iadd = 96,
JVM_OPC_ladd = 97,
JVM_OPC_fadd = 98,
JVM_OPC_dadd = 99,
JVM_OPC_isub = 100,
JVM_OPC_lsub = 101,
JVM_OPC_fsub = 102,
JVM_OPC_dsub = 103,
JVM_OPC_imul = 104,
JVM_OPC_lmul = 105,
JVM_OPC_fmul = 106,
JVM_OPC_dmul = 107,
JVM_OPC_idiv = 108,
JVM_OPC_ldiv = 109,
JVM_OPC_fdiv = 110,
JVM_OPC_ddiv = 111,
JVM_OPC_irem = 112,
JVM_OPC_lrem = 113,
JVM_OPC_frem = 114,
JVM_OPC_drem = 115,
JVM_OPC_ineg = 116,
JVM_OPC_lneg = 117,
JVM_OPC_fneg = 118,
JVM_OPC_dneg = 119,
JVM_OPC_ishl = 120,
JVM_OPC_lshl = 121,
JVM_OPC_ishr = 122,
JVM_OPC_lshr = 123,
JVM_OPC_iushr = 124,
JVM_OPC_lushr = 125,
JVM_OPC_iand = 126,
JVM_OPC_land = 127,
JVM_OPC_ior = 128,
JVM_OPC_lor = 129,
JVM_OPC_ixor = 130,
JVM_OPC_lxor = 131,
JVM_OPC_iinc = 132,
JVM_OPC_i2l = 133,
JVM_OPC_i2f = 134,
JVM_OPC_i2d = 135,
JVM_OPC_l2i = 136,
JVM_OPC_l2f = 137,
JVM_OPC_l2d = 138,
JVM_OPC_f2i = 139,
JVM_OPC_f2l = 140,
JVM_OPC_f2d = 141,
JVM_OPC_d2i = 142,
JVM_OPC_d2l = 143,
JVM_OPC_d2f = 144,
JVM_OPC_i2b = 145,
JVM_OPC_i2c = 146,
JVM_OPC_i2s = 147,
JVM_OPC_lcmp = 148,
JVM_OPC_fcmpl = 149,
JVM_OPC_fcmpg = 150,
JVM_OPC_dcmpl = 151,
JVM_OPC_dcmpg = 152,
JVM_OPC_ifeq = 153,
JVM_OPC_ifne = 154,
JVM_OPC_iflt = 155,
JVM_OPC_ifge = 156,
JVM_OPC_ifgt = 157,
JVM_OPC_ifle = 158,
JVM_OPC_if_icmpeq = 159,
JVM_OPC_if_icmpne = 160,
JVM_OPC_if_icmplt = 161,
JVM_OPC_if_icmpge = 162,
JVM_OPC_if_icmpgt = 163,
JVM_OPC_if_icmple = 164,
JVM_OPC_if_acmpeq = 165,
JVM_OPC_if_acmpne = 166,
JVM_OPC_goto = 167,
JVM_OPC_jsr = 168,
JVM_OPC_ret = 169,
JVM_OPC_tableswitch = 170,
JVM_OPC_lookupswitch = 171,
JVM_OPC_ireturn = 172,
JVM_OPC_lreturn = 173,
JVM_OPC_freturn = 174,
JVM_OPC_dreturn = 175,
JVM_OPC_areturn = 176,
JVM_OPC_return = 177,
JVM_OPC_getstatic = 178,
JVM_OPC_putstatic = 179,
JVM_OPC_getfield = 180,
JVM_OPC_putfield = 181,
JVM_OPC_invokevirtual = 182,
JVM_OPC_invokespecial = 183,
JVM_OPC_invokestatic = 184,
JVM_OPC_invokeinterface = 185,
JVM_OPC_xxxunusedxxx = 186,
JVM_OPC_new = 187,
JVM_OPC_newarray = 188,
JVM_OPC_anewarray = 189,
JVM_OPC_arraylength = 190,
JVM_OPC_athrow = 191,
JVM_OPC_checkcast = 192,
JVM_OPC_instanceof = 193,
JVM_OPC_monitorenter = 194,
JVM_OPC_monitorexit = 195,
JVM_OPC_wide = 196,
JVM_OPC_multianewarray = 197,
JVM_OPC_ifnull = 198,
JVM_OPC_ifnonnull = 199,
JVM_OPC_goto_w = 200,
JVM_OPC_jsr_w = 201,
JVM_OPC_MAX = 201
};
/* Opcode length initializer, use with something like:
* unsigned char opcode_length[JVM_OPC_MAX+1] = JVM_OPCODE_LENGTH_INITIALIZER;
*/
#define JVM_OPCODE_LENGTH_INITIALIZER { \
1, /* nop */ \
1, /* aconst_null */ \
1, /* iconst_m1 */ \
1, /* iconst_0 */ \
1, /* iconst_1 */ \
1, /* iconst_2 */ \
1, /* iconst_3 */ \
1, /* iconst_4 */ \
1, /* iconst_5 */ \
1, /* lconst_0 */ \
1, /* lconst_1 */ \
1, /* fconst_0 */ \
1, /* fconst_1 */ \
1, /* fconst_2 */ \
1, /* dconst_0 */ \
1, /* dconst_1 */ \
2, /* bipush */ \
3, /* sipush */ \
2, /* ldc */ \
3, /* ldc_w */ \
3, /* ldc2_w */ \
2, /* iload */ \
2, /* lload */ \
2, /* fload */ \
2, /* dload */ \
2, /* aload */ \
1, /* iload_0 */ \
1, /* iload_1 */ \
1, /* iload_2 */ \
1, /* iload_3 */ \
1, /* lload_0 */ \
1, /* lload_1 */ \
1, /* lload_2 */ \
1, /* lload_3 */ \
1, /* fload_0 */ \
1, /* fload_1 */ \
1, /* fload_2 */ \
1, /* fload_3 */ \
1, /* dload_0 */ \
1, /* dload_1 */ \
1, /* dload_2 */ \
1, /* dload_3 */ \
1, /* aload_0 */ \
1, /* aload_1 */ \
1, /* aload_2 */ \
1, /* aload_3 */ \
1, /* iaload */ \
1, /* laload */ \
1, /* faload */ \
1, /* daload */ \
1, /* aaload */ \
1, /* baload */ \
1, /* caload */ \
1, /* saload */ \
2, /* istore */ \
2, /* lstore */ \
2, /* fstore */ \
2, /* dstore */ \
2, /* astore */ \
1, /* istore_0 */ \
1, /* istore_1 */ \
1, /* istore_2 */ \
1, /* istore_3 */ \
1, /* lstore_0 */ \
1, /* lstore_1 */ \
1, /* lstore_2 */ \
1, /* lstore_3 */ \
1, /* fstore_0 */ \
1, /* fstore_1 */ \
1, /* fstore_2 */ \
1, /* fstore_3 */ \
1, /* dstore_0 */ \
1, /* dstore_1 */ \
1, /* dstore_2 */ \
1, /* dstore_3 */ \
1, /* astore_0 */ \
1, /* astore_1 */ \
1, /* astore_2 */ \
1, /* astore_3 */ \
1, /* iastore */ \
1, /* lastore */ \
1, /* fastore */ \
1, /* dastore */ \
1, /* aastore */ \
1, /* bastore */ \
1, /* castore */ \
1, /* sastore */ \
1, /* pop */ \
1, /* pop2 */ \
1, /* dup */ \
1, /* dup_x1 */ \
1, /* dup_x2 */ \
1, /* dup2 */ \
1, /* dup2_x1 */ \
1, /* dup2_x2 */ \
1, /* swap */ \
1, /* iadd */ \
1, /* ladd */ \
1, /* fadd */ \
1, /* dadd */ \
1, /* isub */ \
1, /* lsub */ \
1, /* fsub */ \
1, /* dsub */ \
1, /* imul */ \
1, /* lmul */ \
1, /* fmul */ \
1, /* dmul */ \
1, /* idiv */ \
1, /* ldiv */ \
1, /* fdiv */ \
1, /* ddiv */ \
1, /* irem */ \
1, /* lrem */ \
1, /* frem */ \
1, /* drem */ \
1, /* ineg */ \
1, /* lneg */ \
1, /* fneg */ \
1, /* dneg */ \
1, /* ishl */ \
1, /* lshl */ \
1, /* ishr */ \
1, /* lshr */ \
1, /* iushr */ \
1, /* lushr */ \
1, /* iand */ \
1, /* land */ \
1, /* ior */ \
1, /* lor */ \
1, /* ixor */ \
1, /* lxor */ \
3, /* iinc */ \
1, /* i2l */ \
1, /* i2f */ \
1, /* i2d */ \
1, /* l2i */ \
1, /* l2f */ \
1, /* l2d */ \
1, /* f2i */ \
1, /* f2l */ \
1, /* f2d */ \
1, /* d2i */ \
1, /* d2l */ \
1, /* d2f */ \
1, /* i2b */ \
1, /* i2c */ \
1, /* i2s */ \
1, /* lcmp */ \
1, /* fcmpl */ \
1, /* fcmpg */ \
1, /* dcmpl */ \
1, /* dcmpg */ \
3, /* ifeq */ \
3, /* ifne */ \
3, /* iflt */ \
3, /* ifge */ \
3, /* ifgt */ \
3, /* ifle */ \
3, /* if_icmpeq */ \
3, /* if_icmpne */ \
3, /* if_icmplt */ \
3, /* if_icmpge */ \
3, /* if_icmpgt */ \
3, /* if_icmple */ \
3, /* if_acmpeq */ \
3, /* if_acmpne */ \
3, /* goto */ \
3, /* jsr */ \
2, /* ret */ \
99, /* tableswitch */ \
99, /* lookupswitch */ \
1, /* ireturn */ \
1, /* lreturn */ \
1, /* freturn */ \
1, /* dreturn */ \
1, /* areturn */ \
1, /* return */ \
3, /* getstatic */ \
3, /* putstatic */ \
3, /* getfield */ \
3, /* putfield */ \
3, /* invokevirtual */ \
3, /* invokespecial */ \
3, /* invokestatic */ \
5, /* invokeinterface */ \
0, /* xxxunusedxxx */ \
3, /* new */ \
2, /* newarray */ \
3, /* anewarray */ \
1, /* arraylength */ \
1, /* athrow */ \
3, /* checkcast */ \
3, /* instanceof */ \
1, /* monitorenter */ \
1, /* monitorexit */ \
0, /* wide */ \
4, /* multianewarray */ \
3, /* ifnull */ \
3, /* ifnonnull */ \
5, /* goto_w */ \
5 /* jsr_w */ \
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* CLASSFILE_CONSTANTS */

278
jni/jni/jni-headers/jawt.h Normal file
View File

@@ -0,0 +1,278 @@
/*
* %W% %E%
*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
#ifndef _JAVASOFT_JAWT_H_
#define _JAVASOFT_JAWT_H_
#include "jni.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* AWT native interface (new in JDK 1.3)
*
* The AWT native interface allows a native C or C++ application a means
* by which to access native structures in AWT. This is to facilitate moving
* legacy C and C++ applications to Java and to target the needs of the
* community who, at present, wish to do their own native rendering to canvases
* for performance reasons. Standard extensions such as Java3D also require a
* means to access the underlying native data structures of AWT.
*
* There may be future extensions to this API depending on demand.
*
* A VM does not have to implement this API in order to pass the JCK.
* It is recommended, however, that this API is implemented on VMs that support
* standard extensions, such as Java3D.
*
* Since this is a native API, any program which uses it cannot be considered
* 100% pure java.
*/
/*
* AWT Native Drawing Surface (JAWT_DrawingSurface).
*
* For each platform, there is a native drawing surface structure. This
* platform-specific structure can be found in jawt_md.h. It is recommended
* that additional platforms follow the same model. It is also recommended
* that VMs on Win32 and Solaris support the existing structures in jawt_md.h.
*
*******************
* EXAMPLE OF USAGE:
*******************
*
* In Win32, a programmer wishes to access the HWND of a canvas to perform
* native rendering into it. The programmer has declared the paint() method
* for their canvas subclass to be native:
*
*
* MyCanvas.java:
*
* import java.awt.*;
*
* public class MyCanvas extends Canvas {
*
* static {
* System.loadLibrary("mylib");
* }
*
* public native void paint(Graphics g);
* }
*
*
* myfile.c:
*
* #include "jawt_md.h"
* #include <assert.h>
*
* JNIEXPORT void JNICALL
* Java_MyCanvas_paint(JNIEnv* env, jobject canvas, jobject graphics)
* {
* JAWT awt;
* JAWT_DrawingSurface* ds;
* JAWT_DrawingSurfaceInfo* dsi;
* JAWT_Win32DrawingSurfaceInfo* dsi_win;
* jboolean result;
* jint lock;
*
* // Get the AWT
* awt.version = JAWT_VERSION_1_3;
* result = JAWT_GetAWT(env, &awt);
* assert(result != JNI_FALSE);
*
* // Get the drawing surface
* ds = awt.GetDrawingSurface(env, canvas);
* assert(ds != NULL);
*
* // Lock the drawing surface
* lock = ds->Lock(ds);
* assert((lock & JAWT_LOCK_ERROR) == 0);
*
* // Get the drawing surface info
* dsi = ds->GetDrawingSurfaceInfo(ds);
*
* // Get the platform-specific drawing info
* dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
*
* //////////////////////////////
* // !!! DO PAINTING HERE !!! //
* //////////////////////////////
*
* // Free the drawing surface info
* ds->FreeDrawingSurfaceInfo(dsi);
*
* // Unlock the drawing surface
* ds->Unlock(ds);
*
* // Free the drawing surface
* awt.FreeDrawingSurface(ds);
* }
*
*/
/*
* JAWT_Rectangle
* Structure for a native rectangle.
*/
typedef struct jawt_Rectangle {
jint x;
jint y;
jint width;
jint height;
} JAWT_Rectangle;
struct jawt_DrawingSurface;
/*
* JAWT_DrawingSurfaceInfo
* Structure for containing the underlying drawing information of a component.
*/
typedef struct jawt_DrawingSurfaceInfo {
/*
* Pointer to the platform-specific information. This can be safely
* cast to a JAWT_Win32DrawingSurfaceInfo on Windows or a
* JAWT_X11DrawingSurfaceInfo on Solaris. See jawt_md.h for details.
*/
void* platformInfo;
/* Cached pointer to the underlying drawing surface */
struct jawt_DrawingSurface* ds;
/* Bounding rectangle of the drawing surface */
JAWT_Rectangle bounds;
/* Number of rectangles in the clip */
jint clipSize;
/* Clip rectangle array */
JAWT_Rectangle* clip;
} JAWT_DrawingSurfaceInfo;
#define JAWT_LOCK_ERROR 0x00000001
#define JAWT_LOCK_CLIP_CHANGED 0x00000002
#define JAWT_LOCK_BOUNDS_CHANGED 0x00000004
#define JAWT_LOCK_SURFACE_CHANGED 0x00000008
/*
* JAWT_DrawingSurface
* Structure for containing the underlying drawing information of a component.
* All operations on a JAWT_DrawingSurface MUST be performed from the same
* thread as the call to GetDrawingSurface.
*/
typedef struct jawt_DrawingSurface {
/*
* Cached reference to the Java environment of the calling thread.
* If Lock(), Unlock(), GetDrawingSurfaceInfo() or
* FreeDrawingSurfaceInfo() are called from a different thread,
* this data member should be set before calling those functions.
*/
JNIEnv* env;
/* Cached reference to the target object */
jobject target;
/*
* Lock the surface of the target component for native rendering.
* When finished drawing, the surface must be unlocked with
* Unlock(). This function returns a bitmask with one or more of the
* following values:
*
* JAWT_LOCK_ERROR - When an error has occurred and the surface could not
* be locked.
*
* JAWT_LOCK_CLIP_CHANGED - When the clip region has changed.
*
* JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed.
*
* JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed
*/
jint (JNICALL *Lock)
(struct jawt_DrawingSurface* ds);
/*
* Get the drawing surface info.
* The value returned may be cached, but the values may change if
* additional calls to Lock() or Unlock() are made.
* Lock() must be called before this can return a valid value.
* Returns NULL if an error has occurred.
* When finished with the returned value, FreeDrawingSurfaceInfo must be
* called.
*/
JAWT_DrawingSurfaceInfo* (JNICALL *GetDrawingSurfaceInfo)
(struct jawt_DrawingSurface* ds);
/*
* Free the drawing surface info.
*/
void (JNICALL *FreeDrawingSurfaceInfo)
(JAWT_DrawingSurfaceInfo* dsi);
/*
* Unlock the drawing surface of the target component for native rendering.
*/
void (JNICALL *Unlock)
(struct jawt_DrawingSurface* ds);
} JAWT_DrawingSurface;
/*
* JAWT
* Structure for containing native AWT functions.
*/
typedef struct jawt {
/*
* Version of this structure. This must always be set before
* calling JAWT_GetAWT()
*/
jint version;
/*
* Return a drawing surface from a target jobject. This value
* may be cached.
* Returns NULL if an error has occurred.
* Target must be a java.awt.Component (should be a Canvas
* or Window for native rendering).
* FreeDrawingSurface() must be called when finished with the
* returned JAWT_DrawingSurface.
*/
JAWT_DrawingSurface* (JNICALL *GetDrawingSurface)
(JNIEnv* env, jobject target);
/*
* Free the drawing surface allocated in GetDrawingSurface.
*/
void (JNICALL *FreeDrawingSurface)
(JAWT_DrawingSurface* ds);
/*
* Since 1.4
* Locks the entire AWT for synchronization purposes
*/
void (JNICALL *Lock)(JNIEnv* env);
/*
* Since 1.4
* Unlocks the entire AWT for synchronization purposes
*/
void (JNICALL *Unlock)(JNIEnv* env);
/*
* Since 1.4
* Returns a reference to a java.awt.Component from a native
* platform handle. On Windows, this corresponds to an HWND;
* on Solaris and Linux, this is a Drawable. For other platforms,
* see the appropriate machine-dependent header file for a description.
* The reference returned by this function is a local
* reference that is only valid in this environment.
* This function returns a NULL reference if no component could be
* found with matching platform information.
*/
jobject (JNICALL *GetComponent)(JNIEnv* env, void* platformInfo);
} JAWT;
/*
* Get the AWT native structure. This function returns JNI_FALSE if
* an error occurs.
*/
_JNI_IMPORT_OR_EXPORT_
jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt);
#define JAWT_VERSION_1_3 0x00010003
#define JAWT_VERSION_1_4 0x00010004
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* !_JAVASOFT_JAWT_H_ */

View File

@@ -0,0 +1,237 @@
/*
* %W% %E%
*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*
* Java Debug Wire Protocol Transport Service Provider Interface.
*/
#ifndef JDWPTRANSPORT_H
#define JDWPTRANSPORT_H
#include "jni.h"
enum {
JDWPTRANSPORT_VERSION_1_0 = 0x00010000
};
#ifdef __cplusplus
extern "C" {
#endif
struct jdwpTransportNativeInterface_;
struct _jdwpTransportEnv;
#ifdef __cplusplus
typedef _jdwpTransportEnv jdwpTransportEnv;
#else
typedef const struct jdwpTransportNativeInterface_ *jdwpTransportEnv;
#endif /* __cplusplus */
/*
* Errors. Universal errors with JVMTI/JVMDI equivalents keep the
* values the same.
*/
typedef enum {
JDWPTRANSPORT_ERROR_NONE = 0,
JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT = 103,
JDWPTRANSPORT_ERROR_OUT_OF_MEMORY = 110,
JDWPTRANSPORT_ERROR_INTERNAL = 113,
JDWPTRANSPORT_ERROR_ILLEGAL_STATE = 201,
JDWPTRANSPORT_ERROR_IO_ERROR = 202,
JDWPTRANSPORT_ERROR_TIMEOUT = 203,
JDWPTRANSPORT_ERROR_MSG_NOT_AVAILABLE = 204
} jdwpTransportError;
/*
* Structure to define capabilities
*/
typedef struct {
unsigned int can_timeout_attach :1;
unsigned int can_timeout_accept :1;
unsigned int can_timeout_handshake :1;
unsigned int reserved3 :1;
unsigned int reserved4 :1;
unsigned int reserved5 :1;
unsigned int reserved6 :1;
unsigned int reserved7 :1;
unsigned int reserved8 :1;
unsigned int reserved9 :1;
unsigned int reserved10 :1;
unsigned int reserved11 :1;
unsigned int reserved12 :1;
unsigned int reserved13 :1;
unsigned int reserved14 :1;
unsigned int reserved15 :1;
} JDWPTransportCapabilities;
/*
* Structures to define packet layout.
*
* See: http://java.sun.com/j2se/1.5/docs/guide/jpda/jdwp-spec.html
*/
enum {
JDWPTRANSPORT_FLAGS_NONE = 0x0,
JDWPTRANSPORT_FLAGS_REPLY = 0x80
};
typedef struct {
jint len;
jint id;
jbyte flags;
jbyte cmdSet;
jbyte cmd;
jbyte *data;
} jdwpCmdPacket;
typedef struct {
jint len;
jint id;
jbyte flags;
jshort errorCode;
jbyte *data;
} jdwpReplyPacket;
typedef struct {
union {
jdwpCmdPacket cmd;
jdwpReplyPacket reply;
} type;
} jdwpPacket;
/*
* JDWP functions called by the transport.
*/
typedef struct jdwpTransportCallback {
void *(*alloc)(jint numBytes); /* Call this for all allocations */
void (*free)(void *buffer); /* Call this for all deallocations */
} jdwpTransportCallback;
typedef jint (JNICALL *jdwpTransport_OnLoad_t)(JavaVM *jvm,
jdwpTransportCallback *callback,
jint version,
jdwpTransportEnv** env);
/* Function Interface */
struct jdwpTransportNativeInterface_ {
/* 1 : RESERVED */
void *reserved1;
/* 2 : Get Capabilities */
jdwpTransportError (JNICALL *GetCapabilities)(jdwpTransportEnv* env,
JDWPTransportCapabilities *capabilities_ptr);
/* 3 : Attach */
jdwpTransportError (JNICALL *Attach)(jdwpTransportEnv* env,
const char* address,
jlong attach_timeout,
jlong handshake_timeout);
/* 4: StartListening */
jdwpTransportError (JNICALL *StartListening)(jdwpTransportEnv* env,
const char* address,
char** actual_address);
/* 5: StopListening */
jdwpTransportError (JNICALL *StopListening)(jdwpTransportEnv* env);
/* 6: Accept */
jdwpTransportError (JNICALL *Accept)(jdwpTransportEnv* env,
jlong accept_timeout,
jlong handshake_timeout);
/* 7: IsOpen */
jboolean (JNICALL *IsOpen)(jdwpTransportEnv* env);
/* 8: Close */
jdwpTransportError (JNICALL *Close)(jdwpTransportEnv* env);
/* 9: ReadPacket */
jdwpTransportError (JNICALL *ReadPacket)(jdwpTransportEnv* env,
jdwpPacket *pkt);
/* 10: Write Packet */
jdwpTransportError (JNICALL *WritePacket)(jdwpTransportEnv* env,
const jdwpPacket* pkt);
/* 11: GetLastError */
jdwpTransportError (JNICALL *GetLastError)(jdwpTransportEnv* env,
char** error);
};
/*
* Use inlined functions so that C++ code can use syntax such as
* env->Attach("mymachine:5000", 10*1000, 0);
*
* rather than using C's :-
*
* (*env)->Attach(env, "mymachine:5000", 10*1000, 0);
*/
struct _jdwpTransportEnv {
const struct jdwpTransportNativeInterface_ *functions;
#ifdef __cplusplus
jdwpTransportError GetCapabilities(JDWPTransportCapabilities *capabilities_ptr) {
return functions->GetCapabilities(this, capabilities_ptr);
}
jdwpTransportError Attach(const char* address, jlong attach_timeout,
jlong handshake_timeout) {
return functions->Attach(this, address, attach_timeout, handshake_timeout);
}
jdwpTransportError StartListening(const char* address,
char** actual_address) {
return functions->StartListening(this, address, actual_address);
}
jdwpTransportError StopListening(void) {
return functions->StopListening(this);
}
jdwpTransportError Accept(jlong accept_timeout, jlong handshake_timeout) {
return functions->Accept(this, accept_timeout, handshake_timeout);
}
jboolean IsOpen(void) {
return functions->IsOpen(this);
}
jdwpTransportError Close(void) {
return functions->Close(this);
}
jdwpTransportError ReadPacket(jdwpPacket *pkt) {
return functions->ReadPacket(this, pkt);
}
jdwpTransportError WritePacket(const jdwpPacket* pkt) {
return functions->WritePacket(this, pkt);
}
jdwpTransportError GetLastError(char** error) {
return functions->GetLastError(this, error);
}
#endif /* __cplusplus */
};
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* JDWPTRANSPORT_H */

1944
jni/jni/jni-headers/jni.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
/*
* @(#)jawt_md.h 1.13 10/03/23
*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
#ifndef _JAVASOFT_JAWT_MD_H_
#define _JAVASOFT_JAWT_MD_H_
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Intrinsic.h>
#include "jawt.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* X11-specific declarations for AWT native interface.
* See notes in jawt.h for an example of use.
*/
typedef struct jawt_X11DrawingSurfaceInfo {
Drawable drawable;
Display* display;
VisualID visualID;
Colormap colormapID;
int depth;
/*
* Since 1.4
* Returns a pixel value from a set of RGB values.
* This is useful for paletted color (256 color) modes.
*/
int (JNICALL *GetAWTColor)(JAWT_DrawingSurface* ds,
int r, int g, int b);
} JAWT_X11DrawingSurfaceInfo;
#ifdef __cplusplus
}
#endif
#endif /* !_JAVASOFT_JAWT_MD_H_ */

View File

@@ -0,0 +1,24 @@
/*
* @(#)jni_md.h 1.20 10/03/23
*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
#ifndef _JAVASOFT_JNI_MD_H_
#define _JAVASOFT_JNI_MD_H_
#define JNIEXPORT
#define JNIIMPORT
#define JNICALL
typedef int jint;
#ifdef _LP64 /* 64-bit Solaris */
typedef long jlong;
#else
typedef long long jlong;
#endif
typedef signed char jbyte;
#endif /* !_JAVASOFT_JNI_MD_H_ */

View File

@@ -0,0 +1,23 @@
/*
* @(#)jni_md.h 1.19 05/11/17
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
#ifndef _JAVASOFT_JNI_MD_H_
#define _JAVASOFT_JNI_MD_H_
#define JNIEXPORT __attribute__((visibility("default")))
#define JNIIMPORT
#define JNICALL
#if __LP64__
typedef int jint;
#else
typedef long jint;
#endif
typedef long long jlong;
typedef signed char jbyte;
#endif /* !_JAVASOFT_JNI_MD_H_ */

View File

@@ -0,0 +1,41 @@
/*
* %W% %E%
*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
#ifndef _JAVASOFT_JAWT_MD_H_
#define _JAVASOFT_JAWT_MD_H_
#include <windows.h>
#include "jawt.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Win32-specific declarations for AWT native interface.
* See notes in jawt.h for an example of use.
*/
typedef struct jawt_Win32DrawingSurfaceInfo {
/* Native window, DDB, or DIB handle */
union {
HWND hwnd;
HBITMAP hbitmap;
void* pbits;
};
/*
* This HDC should always be used instead of the HDC returned from
* BeginPaint() or any calls to GetDC().
*/
HDC hdc;
HPALETTE hpalette;
} JAWT_Win32DrawingSurfaceInfo;
#ifdef __cplusplus
}
#endif
#endif /* !_JAVASOFT_JAWT_MD_H_ */

View File

@@ -0,0 +1,19 @@
/*
* %W% %E%
*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
#ifndef _JAVASOFT_JNI_MD_H_
#define _JAVASOFT_JNI_MD_H_
#define JNIEXPORT __declspec(dllexport)
#define JNIIMPORT __declspec(dllimport)
#define JNICALL __stdcall
typedef long jint;
typedef __int64 jlong;
typedef signed char jbyte;
#endif /* !_JAVASOFT_JNI_MD_H_ */

1
jni/jni/libtess2 Submodule

Submodule jni/jni/libtess2 added at a43504d78a

18
jni/jni/memcpy_wrap.c Normal file
View File

@@ -0,0 +1,18 @@
#ifndef __ANDROID__
#ifdef __linux__
#ifdef __x86_64__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
void *__wrap_memcpy(void * destination, const void * source, size_t num)
{
return memcpy(destination, source, num);
}
#endif
#endif
#endif

View File

@@ -0,0 +1,237 @@
#include <org.oscim.utils.TessJNI.h>
//@line:114
#include <tesselator.h>
#include <string.h>
#include <stdlib.h>
void* heapAlloc( void* userData, unsigned int size ){
TESS_NOTUSED( userData );
return malloc( size );
}
void* heapRealloc( void *userData, void* ptr, unsigned int size ){
TESS_NOTUSED( userData );
return realloc( ptr, size );
}
void heapFree( void* userData, void* ptr ){
TESS_NOTUSED( userData );
free( ptr );
}
JNIEXPORT jlong JNICALL Java_org_oscim_utils_TessJNI_newTess(JNIEnv* env, jclass clazz, jint size) {
//@line:131
{
if (size <= 0)
return (long)tessNewTess(0);
if (size > 10)
size = 10;
TESSalloc ma;
memset(&ma, 0, sizeof(ma));
ma.memalloc = heapAlloc;
ma.memfree = heapFree;
ma.memrealloc = heapRealloc;
//ma.userData = (void*)&allocated;
ma.meshEdgeBucketSize = 2 << size; // 512
ma.meshVertexBucketSize = 2 << size; // 512
ma.meshFaceBucketSize = 1 << size; // 256
ma.dictNodeBucketSize = 2 << size; // 512
ma.regionBucketSize = 1 << size; // 256
ma.extraVertices = 8;
//ma.extraVertices = 256;
return (long)tessNewTess(&ma);
}
}
JNIEXPORT void JNICALL Java_org_oscim_utils_TessJNI_freeTess(JNIEnv* env, jclass clazz, jlong inst) {
//@line:151
{
tessDeleteTess((TESStesselator*) inst);
}
}
JNIEXPORT void JNICALL Java_org_oscim_utils_TessJNI_addContour(JNIEnv* env, jclass clazz, jlong inst, jint size, jfloatArray obj_contour, jint stride, jint offset, jint count) {
float* contour = (float*)env->GetPrimitiveArrayCritical(obj_contour, 0);
//@line:164
{
tessAddContour((TESStesselator*) inst, size, contour + (offset * stride), stride, count);
}
env->ReleasePrimitiveArrayCritical(obj_contour, contour, 0);
}
JNIEXPORT void JNICALL Java_org_oscim_utils_TessJNI_addMultiContour2D(JNIEnv* env, jclass clazz, jlong inst, jintArray obj_index, jfloatArray obj_contour, jint idxStart, jint idxCount) {
int* index = (int*)env->GetPrimitiveArrayCritical(obj_index, 0);
float* contour = (float*)env->GetPrimitiveArrayCritical(obj_contour, 0);
//@line:167
{
TESStesselator* tess = (TESStesselator*) inst;
int offset = 0;
// start at 0 to get the correct offset in contour..
for (int i = 0; i < idxStart + idxCount; i++){
int len = index[i];
if ((len % 2 != 0) || (len < 0))
break;
if (len < 6 || i < idxStart) {
offset += len;
continue;
}
tessAddContour(tess, 2, contour + offset, 8, len >> 1);
offset += len;
}
}
env->ReleasePrimitiveArrayCritical(obj_index, index, 0);
env->ReleasePrimitiveArrayCritical(obj_contour, contour, 0);
}
JNIEXPORT jint JNICALL Java_org_oscim_utils_TessJNI_tessContour2D(JNIEnv* env, jclass clazz, jlong inst, jint windingRule, jint elementType, jint polySize, jint vertexSize) {
//@line:194
{
return tessTesselate((TESStesselator*) inst, windingRule, elementType, polySize, vertexSize, 0);
}
}
JNIEXPORT jint JNICALL Java_org_oscim_utils_TessJNI_getVertexCount(JNIEnv* env, jclass clazz, jlong inst) {
//@line:197
{
return tessGetVertexCount((TESStesselator*) inst);
}
}
static inline jboolean wrapped_Java_org_oscim_utils_TessJNI_getVertices
(JNIEnv* env, jclass clazz, jlong inst, jfloatArray obj_out, jint offset, jint length, float* out) {
//@line:203
{
const TESSreal* vertices = tessGetVertices((TESStesselator*) inst);
if (!vertices)
return 0;
memcpy(out, vertices + offset, length * sizeof(TESSreal));
return 1;
}
}
JNIEXPORT jboolean JNICALL Java_org_oscim_utils_TessJNI_getVertices(JNIEnv* env, jclass clazz, jlong inst, jfloatArray obj_out, jint offset, jint length) {
float* out = (float*)env->GetPrimitiveArrayCritical(obj_out, 0);
jboolean JNI_returnValue = wrapped_Java_org_oscim_utils_TessJNI_getVertices(env, clazz, inst, obj_out, offset, length, out);
env->ReleasePrimitiveArrayCritical(obj_out, out, 0);
return JNI_returnValue;
}
JNIEXPORT void JNICALL Java_org_oscim_utils_TessJNI_getVerticesS(JNIEnv* env, jclass clazz, jlong inst, jshortArray obj_out, jint offset, jint length, jfloat scale) {
short* out = (short*)env->GetPrimitiveArrayCritical(obj_out, 0);
//@line:213
{
const TESSreal* vertices = tessGetVertices((TESStesselator*) inst);
for(int i = 0; i < length; i++)
out[i] = (short)(vertices[offset++] * scale + 0.5f);
}
env->ReleasePrimitiveArrayCritical(obj_out, out, 0);
}
static inline jboolean wrapped_Java_org_oscim_utils_TessJNI_getVertexIndices
(JNIEnv* env, jclass clazz, jlong inst, jintArray obj_out, jint offset, jint length, int* out) {
//@line:225
{
const TESSindex* indices = tessGetVertexIndices((TESStesselator*) inst);
if (!indices)
return 0;
memcpy(out, indices + offset, length * sizeof(TESSindex));
return 1;
}
}
JNIEXPORT jboolean JNICALL Java_org_oscim_utils_TessJNI_getVertexIndices(JNIEnv* env, jclass clazz, jlong inst, jintArray obj_out, jint offset, jint length) {
int* out = (int*)env->GetPrimitiveArrayCritical(obj_out, 0);
jboolean JNI_returnValue = wrapped_Java_org_oscim_utils_TessJNI_getVertexIndices(env, clazz, inst, obj_out, offset, length, out);
env->ReleasePrimitiveArrayCritical(obj_out, out, 0);
return JNI_returnValue;
}
JNIEXPORT jint JNICALL Java_org_oscim_utils_TessJNI_getElementCount(JNIEnv* env, jclass clazz, jlong inst) {
//@line:235
{
return tessGetElementCount((TESStesselator*) inst);
}
}
static inline jboolean wrapped_Java_org_oscim_utils_TessJNI_getElements
(JNIEnv* env, jclass clazz, jlong inst, jintArray obj_out, jint offset, jint length, int* out) {
//@line:241
{
const TESSindex* elements = tessGetElements((TESStesselator*) inst);
if (!elements)
return 0;
memcpy(out, elements + offset, length * sizeof(TESSindex));
return 1;
}
}
JNIEXPORT jboolean JNICALL Java_org_oscim_utils_TessJNI_getElements(JNIEnv* env, jclass clazz, jlong inst, jintArray obj_out, jint offset, jint length) {
int* out = (int*)env->GetPrimitiveArrayCritical(obj_out, 0);
jboolean JNI_returnValue = wrapped_Java_org_oscim_utils_TessJNI_getElements(env, clazz, inst, obj_out, offset, length, out);
env->ReleasePrimitiveArrayCritical(obj_out, out, 0);
return JNI_returnValue;
}
JNIEXPORT void JNICALL Java_org_oscim_utils_TessJNI_getElementsS(JNIEnv* env, jclass clazz, jlong inst, jshortArray obj_out, jint offset, jint length) {
short* out = (short*)env->GetPrimitiveArrayCritical(obj_out, 0);
//@line:251
{
const TESSindex* elements = tessGetElements((TESStesselator*) inst);
for(int i = 0; i < length; i++)
out[i] = (short)elements[offset++];
}
env->ReleasePrimitiveArrayCritical(obj_out, out, 0);
}
JNIEXPORT void JNICALL Java_org_oscim_utils_TessJNI_getElementsWithInputVertexIds(JNIEnv* env, jclass clazz, jlong inst, jshortArray obj_out, jint dstOffset, jint offset, jint length) {
short* out = (short*)env->GetPrimitiveArrayCritical(obj_out, 0);
//@line:259
{
const TESSindex* elements = tessGetElements((TESStesselator*) inst);
const TESSindex* indices = tessGetVertexIndices((TESStesselator*) inst);
for(int i = 0; i < length; i++)
out[dstOffset++] = (short)(indices[elements[offset++]]);
}
env->ReleasePrimitiveArrayCritical(obj_out, out, 0);
}

View File

@@ -0,0 +1,224 @@
#include <org.oscim.utils.tess.Tesselator.h>
//@line:103
#include <tesselator.h>
#include <string.h>
JNIEXPORT jlong JNICALL Java_org_oscim_utils_tess_Tesselator_newTess(JNIEnv* env, jclass clazz) {
//@line:107
{
return (long)tessNewTess(0);
}
}
JNIEXPORT void JNICALL Java_org_oscim_utils_tess_Tesselator_freeTess(JNIEnv* env, jclass clazz, jlong inst) {
//@line:111
{
tessDeleteTess((TESStesselator*) inst);
}
}
JNIEXPORT void JNICALL Java_org_oscim_utils_tess_Tesselator_addContour(JNIEnv* env, jclass clazz, jlong inst, jint size, jfloatArray obj_contour, jint stride, jint offset, jint count) {
float* contour = (float*)env->GetPrimitiveArrayCritical(obj_contour, 0);
//@line:125
{
tessAddContour((TESStesselator*) inst, size, contour + (offset * stride), stride, count);
}
env->ReleasePrimitiveArrayCritical(obj_contour, contour, 0);
}
JNIEXPORT void JNICALL Java_org_oscim_utils_tess_Tesselator_addMultiContour2D(JNIEnv* env, jclass clazz, jlong inst, jintArray obj_index, jfloatArray obj_contour, jint idxStart, jint idxCount) {
int* index = (int*)env->GetPrimitiveArrayCritical(obj_index, 0);
float* contour = (float*)env->GetPrimitiveArrayCritical(obj_contour, 0);
//@line:129
{
TESStesselator* tess = (TESStesselator*) inst;
int offset = 0;
for (int i = 0; i < idxStart + idxCount; i++){
int len = index[i];
if ((len % 2 != 0) || (len < 0))
break;
if (len < 6 || i < idxStart) {
offset += len;
continue;
}
tessAddContour(tess, 2, contour + offset, 8, len >> 1);
offset += len;
}
}
env->ReleasePrimitiveArrayCritical(obj_index, index, 0);
env->ReleasePrimitiveArrayCritical(obj_contour, contour, 0);
}
JNIEXPORT jint JNICALL Java_org_oscim_utils_tess_Tesselator_tessContour2D(JNIEnv* env, jclass clazz, jlong inst, jint windingRule, jint elementType, jint polySize, jint vertexSize) {
//@line:161
{
return tessTesselate((TESStesselator*) inst, windingRule, elementType, polySize, vertexSize, 0);
}
}
JNIEXPORT jint JNICALL Java_org_oscim_utils_tess_Tesselator_getVertexCount(JNIEnv* env, jclass clazz, jlong inst) {
//@line:165
{
return tessGetVertexCount((TESStesselator*) inst);
}
}
static inline jboolean wrapped_Java_org_oscim_utils_tess_Tesselator_getVertices
(JNIEnv* env, jclass clazz, jlong inst, jfloatArray obj_out, jint offset, jint length, float* out) {
//@line:172
{
const TESSIOreal* vertices = tessGetVertices((TESStesselator*) inst);
//const TESSreal* vertices = tessGetVertices((TESStesselator*) inst);
if (!vertices)
return 0;
memcpy(out, vertices + offset, length * sizeof(TESSIOreal));
//memcpy(out, vertices + offset, length * sizeof(TESSreal));
return 1;
}
}
JNIEXPORT jboolean JNICALL Java_org_oscim_utils_tess_Tesselator_getVertices(JNIEnv* env, jclass clazz, jlong inst, jfloatArray obj_out, jint offset, jint length) {
float* out = (float*)env->GetPrimitiveArrayCritical(obj_out, 0);
jboolean JNI_returnValue = wrapped_Java_org_oscim_utils_tess_Tesselator_getVertices(env, clazz, inst, obj_out, offset, length, out);
env->ReleasePrimitiveArrayCritical(obj_out, out, 0);
return JNI_returnValue;
}
JNIEXPORT void JNICALL Java_org_oscim_utils_tess_Tesselator_getVerticesS(JNIEnv* env, jclass clazz, jlong inst, jshortArray obj_out, jint offset, jint length, jfloat scale) {
short* out = (short*)env->GetPrimitiveArrayCritical(obj_out, 0);
//@line:190
{
const TESSIOreal* vertices = tessGetVertices((TESStesselator*) inst);
//const TESSreal* vertices = tessGetVertices((TESStesselator*) inst);
for(int i = 0; i < length; i++)
out[i] = (short)(vertices[offset++] * scale + 0.5f);
}
env->ReleasePrimitiveArrayCritical(obj_out, out, 0);
}
static inline jboolean wrapped_Java_org_oscim_utils_tess_Tesselator_getVertexIndices
(JNIEnv* env, jclass clazz, jlong inst, jintArray obj_out, jint offset, jint length, int* out) {
//@line:206
{
const TESSindex* indices = tessGetVertexIndices((TESStesselator*) inst);
if (!indices)
return 0;
memcpy(out, indices + offset, length * sizeof(TESSindex));
return 1;
}
}
JNIEXPORT jboolean JNICALL Java_org_oscim_utils_tess_Tesselator_getVertexIndices(JNIEnv* env, jclass clazz, jlong inst, jintArray obj_out, jint offset, jint length) {
int* out = (int*)env->GetPrimitiveArrayCritical(obj_out, 0);
jboolean JNI_returnValue = wrapped_Java_org_oscim_utils_tess_Tesselator_getVertexIndices(env, clazz, inst, obj_out, offset, length, out);
env->ReleasePrimitiveArrayCritical(obj_out, out, 0);
return JNI_returnValue;
}
JNIEXPORT jint JNICALL Java_org_oscim_utils_tess_Tesselator_getElementCount(JNIEnv* env, jclass clazz, jlong inst) {
//@line:218
{
return tessGetElementCount((TESStesselator*) inst);
}
}
static inline jboolean wrapped_Java_org_oscim_utils_tess_Tesselator_getElements
(JNIEnv* env, jclass clazz, jlong inst, jintArray obj_out, jint offset, jint length, int* out) {
//@line:225
{
const TESSindex* elements = tessGetElements((TESStesselator*) inst);
if (!elements)
return 0;
memcpy(out, elements + offset, length * sizeof(TESSindex));
return 1;
}
}
JNIEXPORT jboolean JNICALL Java_org_oscim_utils_tess_Tesselator_getElements(JNIEnv* env, jclass clazz, jlong inst, jintArray obj_out, jint offset, jint length) {
int* out = (int*)env->GetPrimitiveArrayCritical(obj_out, 0);
jboolean JNI_returnValue = wrapped_Java_org_oscim_utils_tess_Tesselator_getElements(env, clazz, inst, obj_out, offset, length, out);
env->ReleasePrimitiveArrayCritical(obj_out, out, 0);
return JNI_returnValue;
}
JNIEXPORT void JNICALL Java_org_oscim_utils_tess_Tesselator_getElementsS(JNIEnv* env, jclass clazz, jlong inst, jshortArray obj_out, jint offset, jint length) {
short* out = (short*)env->GetPrimitiveArrayCritical(obj_out, 0);
//@line:238
{
const TESSindex* elements = tessGetElements((TESStesselator*) inst);
for(int i = 0; i < length; i++)
out[i] = (short)elements[offset++];
}
env->ReleasePrimitiveArrayCritical(obj_out, out, 0);
}
JNIEXPORT void JNICALL Java_org_oscim_utils_tess_Tesselator_getElementsWithInputVertexIds(JNIEnv* env, jclass clazz, jlong inst, jshortArray obj_out, jint dstOffset, jint offset, jint length) {
short* out = (short*)env->GetPrimitiveArrayCritical(obj_out, 0);
//@line:247
{
const TESSindex* elements = tessGetElements((TESStesselator*) inst);
const TESSindex* indices = tessGetVertexIndices((TESStesselator*) inst);
for(int i = 0; i < length; i++)
out[dstOffset++] = (short)indices[elements[offset++]];
}
env->ReleasePrimitiveArrayCritical(obj_out, out, 0);
}

View File

@@ -0,0 +1,155 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_oscim_utils_tess_Tesselator */
#ifndef _Included_org_oscim_utils_tess_Tesselator
#define _Included_org_oscim_utils_tess_Tesselator
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_oscim_utils_tess_Tesselator
* Method: newTess
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_org_oscim_utils_tess_Tesselator_newTess
(JNIEnv *, jclass);
/*
* Class: org_oscim_utils_tess_Tesselator
* Method: freeTess
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_oscim_utils_tess_Tesselator_freeTess
(JNIEnv *, jclass, jlong);
/*
* Class: org_oscim_utils_tess_Tesselator
* Method: addContour
* Signature: (JI[FIII)V
*/
JNIEXPORT void JNICALL Java_org_oscim_utils_tess_Tesselator_addContour
(JNIEnv *, jclass, jlong, jint, jfloatArray, jint, jint, jint);
/*
* Class: org_oscim_utils_tess_Tesselator
* Method: addMultiContour2D
* Signature: (J[I[FII)V
*/
JNIEXPORT void JNICALL Java_org_oscim_utils_tess_Tesselator_addMultiContour2D
(JNIEnv *, jclass, jlong, jintArray, jfloatArray, jint, jint);
/*
* Class: org_oscim_utils_tess_Tesselator
* Method: tessContour2D
* Signature: (JIIII)I
*/
JNIEXPORT jint JNICALL Java_org_oscim_utils_tess_Tesselator_tessContour2D
(JNIEnv *, jclass, jlong, jint, jint, jint, jint);
/*
* Class: org_oscim_utils_tess_Tesselator
* Method: getVertexCount
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_org_oscim_utils_tess_Tesselator_getVertexCount
(JNIEnv *, jclass, jlong);
/*
* Class: org_oscim_utils_tess_Tesselator
* Method: getVertices
* Signature: (J[FII)Z
*/
JNIEXPORT jboolean JNICALL Java_org_oscim_utils_tess_Tesselator_getVertices
(JNIEnv *, jclass, jlong, jfloatArray, jint, jint);
/*
* Class: org_oscim_utils_tess_Tesselator
* Method: getVerticesS
* Signature: (J[SIIF)V
*/
JNIEXPORT void JNICALL Java_org_oscim_utils_tess_Tesselator_getVerticesS
(JNIEnv *, jclass, jlong, jshortArray, jint, jint, jfloat);
/*
* Class: org_oscim_utils_tess_Tesselator
* Method: getVertexIndices
* Signature: (J[III)Z
*/
JNIEXPORT jboolean JNICALL Java_org_oscim_utils_tess_Tesselator_getVertexIndices
(JNIEnv *, jclass, jlong, jintArray, jint, jint);
/*
* Class: org_oscim_utils_tess_Tesselator
* Method: getElementCount
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_org_oscim_utils_tess_Tesselator_getElementCount
(JNIEnv *, jclass, jlong);
/*
* Class: org_oscim_utils_tess_Tesselator
* Method: getElements
* Signature: (J[III)Z
*/
JNIEXPORT jboolean JNICALL Java_org_oscim_utils_tess_Tesselator_getElements
(JNIEnv *, jclass, jlong, jintArray, jint, jint);
/*
* Class: org_oscim_utils_tess_Tesselator
* Method: getElementsS
* Signature: (J[SII)V
*/
JNIEXPORT void JNICALL Java_org_oscim_utils_tess_Tesselator_getElementsS
(JNIEnv *, jclass, jlong, jshortArray, jint, jint);
/*
* Class: org_oscim_utils_tess_Tesselator
* Method: getElementsWithInputVertexIds
* Signature: (J[SIII)V
*/
JNIEXPORT void JNICALL Java_org_oscim_utils_tess_Tesselator_getElementsWithInputVertexIds
(JNIEnv *, jclass, jlong, jshortArray, jint, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
/* Header for class org_oscim_utils_tess_Tesselator_ElementType */
#ifndef _Included_org_oscim_utils_tess_Tesselator_ElementType
#define _Included_org_oscim_utils_tess_Tesselator_ElementType
#ifdef __cplusplus
extern "C" {
#endif
#undef org_oscim_utils_tess_Tesselator_ElementType_POLYGONS
#define org_oscim_utils_tess_Tesselator_ElementType_POLYGONS 0L
#undef org_oscim_utils_tess_Tesselator_ElementType_CONNECTED_POLYGONS
#define org_oscim_utils_tess_Tesselator_ElementType_CONNECTED_POLYGONS 1L
#undef org_oscim_utils_tess_Tesselator_ElementType_BOUNDARY_CONTOURS
#define org_oscim_utils_tess_Tesselator_ElementType_BOUNDARY_CONTOURS 2L
#ifdef __cplusplus
}
#endif
#endif
/* Header for class org_oscim_utils_tess_Tesselator_WindingRule */
#ifndef _Included_org_oscim_utils_tess_Tesselator_WindingRule
#define _Included_org_oscim_utils_tess_Tesselator_WindingRule
#ifdef __cplusplus
extern "C" {
#endif
#undef org_oscim_utils_tess_Tesselator_WindingRule_ODD
#define org_oscim_utils_tess_Tesselator_WindingRule_ODD 0L
#undef org_oscim_utils_tess_Tesselator_WindingRule_NONZERO
#define org_oscim_utils_tess_Tesselator_WindingRule_NONZERO 1L
#undef org_oscim_utils_tess_Tesselator_WindingRule_POSITIVE
#define org_oscim_utils_tess_Tesselator_WindingRule_POSITIVE 2L
#undef org_oscim_utils_tess_Tesselator_WindingRule_NEGATIVE
#define org_oscim_utils_tess_Tesselator_WindingRule_NEGATIVE 3L
#undef org_oscim_utils_tess_Tesselator_WindingRule_ABS_GEQ_TWO
#define org_oscim_utils_tess_Tesselator_WindingRule_ABS_GEQ_TWO 4L
#ifdef __cplusplus
}
#endif
#endif