From 22262166e07de99ae0d4557e4f87e3bd1c5cd6dd Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Wed, 31 Mar 2010 21:12:09 +0200 Subject: introduced com.jogamp.common.{nio,os} packages and moved some classes. --- src/java/com/jogamp/common/nio/Buffers.java | 707 +++++++++++++++++++++ src/java/com/jogamp/common/nio/Int64Buffer.java | 170 +++++ .../jogamp/common/nio/Int64BufferME_CDC_FP.java | 95 +++ src/java/com/jogamp/common/nio/Int64BufferSE.java | 80 +++ src/java/com/jogamp/common/nio/NativeBuffer.java | 47 ++ src/java/com/jogamp/common/nio/PointerBuffer.java | 227 +++++++ .../jogamp/common/nio/PointerBufferME_CDC_FP.java | 103 +++ .../com/jogamp/common/nio/PointerBufferSE.java | 93 +++ src/java/com/jogamp/common/nio/StructAccessor.java | 327 ++++++++++ src/java/com/jogamp/common/os/DynamicLinker.java | 50 ++ .../com/jogamp/common/os/DynamicLookupHelper.java | 53 ++ .../jogamp/common/os/MacOSXDynamicLinkerImpl.java | 58 ++ src/java/com/jogamp/common/os/NativeLibrary.java | 426 +++++++++++++ src/java/com/jogamp/common/os/Platform.java | 163 +++++ .../jogamp/common/os/UnixDynamicLinkerImpl.java | 64 ++ .../jogamp/common/os/WindowsDynamicLinkerImpl.java | 47 ++ src/java/com/jogamp/gluegen/runtime/Buffers.java | 706 -------------------- .../com/jogamp/gluegen/runtime/DynamicLinker.java | 50 -- .../gluegen/runtime/DynamicLookupHelper.java | 53 -- .../com/jogamp/gluegen/runtime/Int64Buffer.java | 169 ----- .../gluegen/runtime/Int64BufferME_CDC_FP.java | 94 --- .../com/jogamp/gluegen/runtime/Int64BufferSE.java | 80 --- .../gluegen/runtime/MacOSXDynamicLinkerImpl.java | 60 -- .../com/jogamp/gluegen/runtime/NativeBuffer.java | 48 -- .../com/jogamp/gluegen/runtime/NativeLibrary.java | 425 ------------- src/java/com/jogamp/gluegen/runtime/Platform.java | 162 ----- .../com/jogamp/gluegen/runtime/PointerBuffer.java | 225 ------- .../gluegen/runtime/PointerBufferME_CDC_FP.java | 102 --- .../jogamp/gluegen/runtime/PointerBufferSE.java | 92 --- .../jogamp/gluegen/runtime/ProcAddressHelper.java | 1 + .../com/jogamp/gluegen/runtime/StructAccessor.java | 326 ---------- .../gluegen/runtime/UnixDynamicLinkerImpl.java | 66 -- .../gluegen/runtime/WindowsDynamicLinkerImpl.java | 49 -- .../runtime/opengl/GLProcAddressHelper.java | 1 + src/java/com/sun/gluegen/JavaEmitter.java | 4 + src/java/com/sun/gluegen/JavaType.java | 12 +- .../sun/gluegen/test/TestPointerBufferEndian.java | 4 +- .../sun/gluegen/test/TestStructAccessorEndian.java | 4 +- .../com/jogamp/gluegen/test/junit/BaseTest1.java | 8 +- .../gluegen/test/junit/Test1p1JavaEmitter.java | 4 +- .../test/junit/Test1p2ProcAddressEmitter.java | 8 +- .../com/jogamp/gluegen/test/junit/test1-common.cfg | 3 + .../jogamp/gluegen/test/junit/test1p2-gluegen.cfg | 1 - src/native/common/Platform.c | 2 +- src/native/common/PointerBuffer.c | 2 +- src/native/macosx/MacOSXDynamicLinkerImpl_JNI.c | 16 +- src/native/unix/UnixDynamicLinkerImpl_JNI.c | 16 +- src/native/windows/WindowsDynamicLinkerImpl_JNI.c | 16 +- 48 files changed, 2766 insertions(+), 2753 deletions(-) create mode 100755 src/java/com/jogamp/common/nio/Buffers.java create mode 100644 src/java/com/jogamp/common/nio/Int64Buffer.java create mode 100755 src/java/com/jogamp/common/nio/Int64BufferME_CDC_FP.java create mode 100755 src/java/com/jogamp/common/nio/Int64BufferSE.java create mode 100644 src/java/com/jogamp/common/nio/NativeBuffer.java create mode 100644 src/java/com/jogamp/common/nio/PointerBuffer.java create mode 100755 src/java/com/jogamp/common/nio/PointerBufferME_CDC_FP.java create mode 100755 src/java/com/jogamp/common/nio/PointerBufferSE.java create mode 100644 src/java/com/jogamp/common/nio/StructAccessor.java create mode 100755 src/java/com/jogamp/common/os/DynamicLinker.java create mode 100755 src/java/com/jogamp/common/os/DynamicLookupHelper.java create mode 100755 src/java/com/jogamp/common/os/MacOSXDynamicLinkerImpl.java create mode 100755 src/java/com/jogamp/common/os/NativeLibrary.java create mode 100644 src/java/com/jogamp/common/os/Platform.java create mode 100755 src/java/com/jogamp/common/os/UnixDynamicLinkerImpl.java create mode 100755 src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java delete mode 100755 src/java/com/jogamp/gluegen/runtime/Buffers.java delete mode 100755 src/java/com/jogamp/gluegen/runtime/DynamicLinker.java delete mode 100755 src/java/com/jogamp/gluegen/runtime/DynamicLookupHelper.java delete mode 100644 src/java/com/jogamp/gluegen/runtime/Int64Buffer.java delete mode 100755 src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java delete mode 100755 src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java delete mode 100755 src/java/com/jogamp/gluegen/runtime/MacOSXDynamicLinkerImpl.java delete mode 100644 src/java/com/jogamp/gluegen/runtime/NativeBuffer.java delete mode 100755 src/java/com/jogamp/gluegen/runtime/NativeLibrary.java delete mode 100644 src/java/com/jogamp/gluegen/runtime/Platform.java delete mode 100644 src/java/com/jogamp/gluegen/runtime/PointerBuffer.java delete mode 100755 src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java delete mode 100755 src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java delete mode 100644 src/java/com/jogamp/gluegen/runtime/StructAccessor.java delete mode 100755 src/java/com/jogamp/gluegen/runtime/UnixDynamicLinkerImpl.java delete mode 100755 src/java/com/jogamp/gluegen/runtime/WindowsDynamicLinkerImpl.java (limited to 'src') diff --git a/src/java/com/jogamp/common/nio/Buffers.java b/src/java/com/jogamp/common/nio/Buffers.java new file mode 100755 index 0000000..e3bea17 --- /dev/null +++ b/src/java/com/jogamp/common/nio/Buffers.java @@ -0,0 +1,707 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ +package com.jogamp.common.nio; + +import com.jogamp.common.os.Platform; +import java.nio.*; + +/** + * @author Kenneth Russel + * @author Sven Gothel + * @author Michael Bien + */ +public class Buffers { + + public static final int SIZEOF_BYTE = 1; + public static final int SIZEOF_SHORT = 2; + public static final int SIZEOF_CHAR = 2; + public static final int SIZEOF_INT = 4; + public static final int SIZEOF_FLOAT = 4; + public static final int SIZEOF_LONG = 8; + public static final int SIZEOF_DOUBLE = 8; + + protected Buffers() {} + + /** + * Allocates a new direct ByteBuffer with the specified number of + * elements. The returned buffer will have its byte order set to + * the host platform's native byte order. + */ + public static ByteBuffer newDirectByteBuffer(int numElements) { + return nativeOrder(ByteBuffer.allocateDirect(numElements)); + } + + public static ByteBuffer newDirectByteBuffer(byte[] values, int offset, int lenght) { + return (ByteBuffer)newDirectByteBuffer(lenght).put(values, offset, lenght).rewind(); + } + + public static ByteBuffer newDirectByteBuffer(byte[] values, int offset) { + return newDirectByteBuffer(values, offset, values.length-offset); + } + + public static ByteBuffer newDirectByteBuffer(byte[] values) { + return newDirectByteBuffer(values, 0); + } + + /** + * Allocates a new direct DoubleBuffer with the specified number of + * elements. The returned buffer will have its byte order set to + * the host platform's native byte order. + */ + public static DoubleBuffer newDirectDoubleBuffer(int numElements) { + return newDirectByteBuffer(numElements * SIZEOF_DOUBLE).asDoubleBuffer(); + } + + public static DoubleBuffer newDirectDoubleBuffer(double[] values, int offset, int lenght) { + return (DoubleBuffer)newDirectDoubleBuffer(lenght).put(values, offset, lenght).rewind(); + } + + public static DoubleBuffer newDirectDoubleBuffer(double[] values, int offset) { + return newDirectDoubleBuffer(values, offset, values.length - offset); + } + + public static DoubleBuffer newDirectDoubleBuffer(double[] values) { + return newDirectDoubleBuffer(values, 0); + } + + /** + * Allocates a new direct FloatBuffer with the specified number of + * elements. The returned buffer will have its byte order set to + * the host platform's native byte order. + */ + public static FloatBuffer newDirectFloatBuffer(int numElements) { + return newDirectByteBuffer(numElements * SIZEOF_FLOAT).asFloatBuffer(); + } + + public static FloatBuffer newDirectFloatBuffer(float[] values, int offset, int lenght) { + return (FloatBuffer)newDirectFloatBuffer(lenght).put(values, offset, lenght).rewind(); + } + + public static FloatBuffer newDirectFloatBuffer(float[] values, int offset) { + return newDirectFloatBuffer(values, offset, values.length - offset); + } + + public static FloatBuffer newDirectFloatBuffer(float[] values) { + return newDirectFloatBuffer(values, 0); + } + + /** + * Allocates a new direct IntBuffer with the specified number of + * elements. The returned buffer will have its byte order set to + * the host platform's native byte order. + */ + public static IntBuffer newDirectIntBuffer(int numElements) { + return newDirectByteBuffer(numElements * SIZEOF_INT).asIntBuffer(); + } + + public static IntBuffer newDirectIntBuffer(int[] values, int offset, int lenght) { + return (IntBuffer)newDirectIntBuffer(lenght).put(values, offset, lenght).rewind(); + } + + public static IntBuffer newDirectIntBuffer(int[] values, int offset) { + return newDirectIntBuffer(values, offset, values.length - offset); + } + + public static IntBuffer newDirectIntBuffer(int[] values) { + return newDirectIntBuffer(values, 0); + } + + /** + * Allocates a new direct LongBuffer with the specified number of + * elements. The returned buffer will have its byte order set to + * the host platform's native byte order. + */ + public static LongBuffer newDirectLongBuffer(int numElements) { + return newDirectByteBuffer(numElements * SIZEOF_LONG).asLongBuffer(); + } + + public static LongBuffer newDirectLongBuffer(long[] values, int offset, int lenght) { + return (LongBuffer)newDirectLongBuffer(lenght).put(values, offset, lenght).rewind(); + } + + public static LongBuffer newDirectLongBuffer(long[] values, int offset) { + return newDirectLongBuffer(values, offset, values.length - offset); + } + + public static LongBuffer newDirectLongBuffer(long[] values) { + return newDirectLongBuffer(values, 0); + } + + /** + * Allocates a new direct ShortBuffer with the specified number of + * elements. The returned buffer will have its byte order set to + * the host platform's native byte order. + */ + public static ShortBuffer newDirectShortBuffer(int numElements) { + return newDirectByteBuffer(numElements * SIZEOF_SHORT).asShortBuffer(); + } + + public static ShortBuffer newDirectShortBuffer(short[] values, int offset, int lenght) { + return (ShortBuffer)newDirectShortBuffer(lenght).put(values, offset, lenght).rewind(); + } + + public static ShortBuffer newDirectShortBuffer(short[] values, int offset) { + return newDirectShortBuffer(values, offset, values.length - offset); + } + + public static ShortBuffer newDirectShortBuffer(short[] values) { + return newDirectShortBuffer(values, 0); + } + + /** + * Allocates a new direct CharBuffer with the specified number of + * elements. The returned buffer will have its byte order set to + * the host platform's native byte order. + */ + public static CharBuffer newDirectCharBuffer(int numElements) { + return newDirectByteBuffer(numElements * SIZEOF_SHORT).asCharBuffer(); + } + + public static CharBuffer newDirectCharBuffer(char[] values, int offset, int lenght) { + return (CharBuffer)newDirectCharBuffer(lenght).put(values, offset, lenght).rewind(); + } + + public static CharBuffer newDirectCharBuffer(char[] values, int offset) { + return newDirectCharBuffer(values, offset, values.length - offset); + } + + public static CharBuffer newDirectCharBuffer(char[] values) { + return newDirectCharBuffer(values, 0); + } + + /** + * Helper routine to set a ByteBuffer to the native byte order, if + * that operation is supported by the underlying NIO + * implementation. + */ + public static ByteBuffer nativeOrder(ByteBuffer buf) { + if (Platform.isJavaSE()) { + return buf.order(ByteOrder.nativeOrder()); + } else { + // JSR 239 does not support the ByteOrder class or the order methods. + // The initial order of a byte buffer is the platform byte order. + return buf; + } + } + + /** + * Returns the size of a single element of this buffer in bytes. + */ + public static final int sizeOfBufferElem(Buffer buffer) { + if (buffer == null) { + return 0; + } + if (buffer instanceof ByteBuffer) { + return SIZEOF_BYTE; + } else if (buffer instanceof IntBuffer) { + return SIZEOF_INT; + } else if (buffer instanceof ShortBuffer) { + return SIZEOF_SHORT; + } else if (buffer instanceof FloatBuffer) { + return SIZEOF_FLOAT; + } else if (Platform.isJavaSE()) { + if (buffer instanceof DoubleBuffer) { + return SIZEOF_DOUBLE; + } else if (buffer instanceof LongBuffer) { + return SIZEOF_LONG; + } else if (buffer instanceof CharBuffer) { + return SIZEOF_CHAR; + } + } + throw new RuntimeException("Unexpected buffer type " + buffer.getClass().getName()); + } + + /** + * Helper routine to tell whether a buffer is direct or not. Null + * pointers are considered NOT direct. isDirect() should really be + * public in Buffer and not replicated in all subclasses. + */ + public static boolean isDirect(Object buf) { + if (buf == null) { + return true; + } + if (buf instanceof ByteBuffer) { + return ((ByteBuffer) buf).isDirect(); + } else if (buf instanceof FloatBuffer) { + return ((FloatBuffer) buf).isDirect(); + } else if (buf instanceof IntBuffer) { + return ((IntBuffer) buf).isDirect(); + } else if (buf instanceof ShortBuffer) { + return ((ShortBuffer) buf).isDirect(); + } else if (buf instanceof Int64Buffer) { + return ((Int64Buffer) buf).isDirect(); + } else if (buf instanceof PointerBuffer) { + return ((PointerBuffer) buf).isDirect(); + } else if (Platform.isJavaSE()) { + if (buf instanceof DoubleBuffer) { + return ((DoubleBuffer) buf).isDirect(); + } else if (buf instanceof LongBuffer) { + return ((LongBuffer) buf).isDirect(); + }else if (buf instanceof CharBuffer) { + return ((CharBuffer) buf).isDirect(); + } + } + throw new RuntimeException("Unexpected buffer type " + buf.getClass().getName()); + } + + /** + * Helper routine to get the Buffer byte offset by taking into + * account the Buffer position and the underlying type. This is + * the total offset for Direct Buffers. + */ + public static int getDirectBufferByteOffset(Object buf) { + if (buf == null) { + return 0; + } + if (buf instanceof Buffer) { + int pos = ((Buffer) buf).position(); + if (buf instanceof ByteBuffer) { + return pos; + } else if (buf instanceof FloatBuffer) { + return pos * SIZEOF_FLOAT; + } else if (buf instanceof IntBuffer) { + return pos * SIZEOF_INT; + } else if (buf instanceof ShortBuffer) { + return pos * SIZEOF_SHORT; + }else if(Platform.isJavaSE()) { + if (buf instanceof DoubleBuffer) { + return pos * SIZEOF_DOUBLE; + } else if (buf instanceof LongBuffer) { + return pos * SIZEOF_LONG; + } else if (buf instanceof CharBuffer) { + return pos * SIZEOF_CHAR; + } + } + } else if (buf instanceof Int64Buffer) { + Int64Buffer int64Buffer = (Int64Buffer) buf; + return int64Buffer.position() * Int64Buffer.elementSize(); + } else if (buf instanceof PointerBuffer) { + PointerBuffer pointerBuffer = (PointerBuffer) buf; + return pointerBuffer.position() * PointerBuffer.elementSize(); + } + + throw new RuntimeException("Disallowed array backing store type in buffer " + buf.getClass().getName()); + } + + /** + * Helper routine to return the array backing store reference from + * a Buffer object. + */ + public static Object getArray(Object buf) { + if (buf == null) { + return null; + } + if (buf instanceof ByteBuffer) { + return ((ByteBuffer) buf).array(); + } else if (buf instanceof FloatBuffer) { + return ((FloatBuffer) buf).array(); + } else if (buf instanceof IntBuffer) { + return ((IntBuffer) buf).array(); + } else if (buf instanceof ShortBuffer) { + return ((ShortBuffer) buf).array(); + } else if (buf instanceof Int64Buffer) { + return ((Int64Buffer) buf).array(); + } else if (buf instanceof PointerBuffer) { + return ((PointerBuffer) buf).array(); + }else if(Platform.isJavaSE()) { + if (buf instanceof DoubleBuffer) { + return ((DoubleBuffer) buf).array(); + } else if (buf instanceof LongBuffer) { + return ((LongBuffer) buf).array(); + } else if (buf instanceof CharBuffer) { + return ((CharBuffer) buf).array(); + } + } + + throw new RuntimeException("Disallowed array backing store type in buffer " + buf.getClass().getName()); + } + + /** + * Helper routine to get the full byte offset from the beginning of + * the array that is the storage for the indirect Buffer + * object. The array offset also includes the position offset + * within the buffer, in addition to any array offset. + */ + public static int getIndirectBufferByteOffset(Object buf) { + if (buf == null) { + return 0; + } + if (buf instanceof Buffer) { + int pos = ((Buffer) buf).position(); + if (buf instanceof ByteBuffer) { + return (((ByteBuffer) buf).arrayOffset() + pos); + } else if (buf instanceof FloatBuffer) { + return (SIZEOF_FLOAT * (((FloatBuffer) buf).arrayOffset() + pos)); + } else if (buf instanceof IntBuffer) { + return (SIZEOF_INT * (((IntBuffer) buf).arrayOffset() + pos)); + } else if (buf instanceof ShortBuffer) { + return (SIZEOF_SHORT * (((ShortBuffer) buf).arrayOffset() + pos)); + }else if(Platform.isJavaSE()) { + if (buf instanceof DoubleBuffer) { + return (SIZEOF_DOUBLE * (((DoubleBuffer) buf).arrayOffset() + pos)); + } else if (buf instanceof LongBuffer) { + return (SIZEOF_LONG * (((LongBuffer) buf).arrayOffset() + pos)); + } else if (buf instanceof CharBuffer) { + return (SIZEOF_CHAR * (((CharBuffer) buf).arrayOffset() + pos)); + } + } + } else if (buf instanceof Int64Buffer) { + Int64Buffer int64Buffer = (Int64Buffer) buf; + return Int64Buffer.elementSize() * (int64Buffer.arrayOffset() + int64Buffer.position()); + } else if (buf instanceof PointerBuffer) { + PointerBuffer pointerBuffer = (PointerBuffer) buf; + return PointerBuffer.elementSize() * (pointerBuffer.arrayOffset() + pointerBuffer.position()); + } + + throw new RuntimeException("Unknown buffer type " + buf.getClass().getName()); + } + + + //---------------------------------------------------------------------- + // Copy routines (type-to-type) + // + /** + * Copies the remaining elements (as defined by + * limit() - position()) in the passed ByteBuffer into + * a newly-allocated direct ByteBuffer. The returned buffer will + * have its byte order set to the host platform's native byte + * order. The position of the newly-allocated buffer will be zero, + * and the position of the passed buffer is unchanged (though its + * mark is changed). + */ + public static ByteBuffer copyByteBuffer(ByteBuffer orig) { + ByteBuffer dest = newDirectByteBuffer(orig.remaining()); + dest.put(orig); + dest.rewind(); + return dest; + } + + /** + * Copies the remaining elements (as defined by + * limit() - position()) in the passed FloatBuffer + * into a newly-allocated direct FloatBuffer. The returned buffer + * will have its byte order set to the host platform's native byte + * order. The position of the newly-allocated buffer will be zero, + * and the position of the passed buffer is unchanged (though its + * mark is changed). + */ + public static FloatBuffer copyFloatBuffer(FloatBuffer orig) { + return copyFloatBufferAsByteBuffer(orig).asFloatBuffer(); + } + + /** + * Copies the remaining elements (as defined by + * limit() - position()) in the passed IntBuffer + * into a newly-allocated direct IntBuffer. The returned buffer + * will have its byte order set to the host platform's native byte + * order. The position of the newly-allocated buffer will be zero, + * and the position of the passed buffer is unchanged (though its + * mark is changed). + */ + public static IntBuffer copyIntBuffer(IntBuffer orig) { + return copyIntBufferAsByteBuffer(orig).asIntBuffer(); + } + + /** + * Copies the remaining elements (as defined by + * limit() - position()) in the passed ShortBuffer + * into a newly-allocated direct ShortBuffer. The returned buffer + * will have its byte order set to the host platform's native byte + * order. The position of the newly-allocated buffer will be zero, + * and the position of the passed buffer is unchanged (though its + * mark is changed). + */ + public static ShortBuffer copyShortBuffer(ShortBuffer orig) { + return copyShortBufferAsByteBuffer(orig).asShortBuffer(); + } + + //---------------------------------------------------------------------- + // Copy routines (type-to-ByteBuffer) + // + /** + * Copies the remaining elements (as defined by + * limit() - position()) in the passed FloatBuffer + * into a newly-allocated direct ByteBuffer. The returned buffer + * will have its byte order set to the host platform's native byte + * order. The position of the newly-allocated buffer will be zero, + * and the position of the passed buffer is unchanged (though its + * mark is changed). + */ + public static ByteBuffer copyFloatBufferAsByteBuffer(FloatBuffer orig) { + ByteBuffer dest = newDirectByteBuffer(orig.remaining() * SIZEOF_FLOAT); + dest.asFloatBuffer().put(orig); + dest.rewind(); + return dest; + } + + /** + * Copies the remaining elements (as defined by + * limit() - position()) in the passed IntBuffer into + * a newly-allocated direct ByteBuffer. The returned buffer will + * have its byte order set to the host platform's native byte + * order. The position of the newly-allocated buffer will be zero, + * and the position of the passed buffer is unchanged (though its + * mark is changed). + */ + public static ByteBuffer copyIntBufferAsByteBuffer(IntBuffer orig) { + ByteBuffer dest = newDirectByteBuffer(orig.remaining() * SIZEOF_INT); + dest.asIntBuffer().put(orig); + dest.rewind(); + return dest; + } + + /** + * Copies the remaining elements (as defined by + * limit() - position()) in the passed ShortBuffer + * into a newly-allocated direct ByteBuffer. The returned buffer + * will have its byte order set to the host platform's native byte + * order. The position of the newly-allocated buffer will be zero, + * and the position of the passed buffer is unchanged (though its + * mark is changed). + */ + public static ByteBuffer copyShortBufferAsByteBuffer(ShortBuffer orig) { + ByteBuffer dest = newDirectByteBuffer(orig.remaining() * SIZEOF_SHORT); + dest.asShortBuffer().put(orig); + dest.rewind(); + return dest; + } + + //---------------------------------------------------------------------- + // Conversion routines + // + public final static FloatBuffer getFloatBuffer(DoubleBuffer source) { + source.rewind(); + FloatBuffer dest = newDirectFloatBuffer(source.limit()); + while (source.hasRemaining()) { + dest.put((float) source.get()); + } + return dest; + } + + //---------------------------------------------------------------------- + // Convenient put methods with generic target Buffer + // + public static Buffer put(Buffer dest, Buffer src) { + if ((dest instanceof ByteBuffer) && (src instanceof ByteBuffer)) { + return ((ByteBuffer) dest).put((ByteBuffer) src); + } else if ((dest instanceof ShortBuffer) && (src instanceof ShortBuffer)) { + return ((ShortBuffer) dest).put((ShortBuffer) src); + } else if ((dest instanceof IntBuffer) && (src instanceof IntBuffer)) { + return ((IntBuffer) dest).put((IntBuffer) src); + } else if ((dest instanceof FloatBuffer) && (src instanceof FloatBuffer)) { + return ((FloatBuffer) dest).put((FloatBuffer) src); + } else if (Platform.isJavaSE()) { + if ((dest instanceof LongBuffer) && (src instanceof LongBuffer)) { + return ((LongBuffer) dest).put((LongBuffer) src); + } else if ((dest instanceof DoubleBuffer) && (src instanceof DoubleBuffer)) { + return ((DoubleBuffer) dest).put((DoubleBuffer) src); + } else if ((dest instanceof CharBuffer) && (src instanceof CharBuffer)) { + return ((CharBuffer) dest).put((CharBuffer) src); + } + } + throw new RuntimeException("Incompatible Buffer classes: dest = " + dest.getClass().getName() + ", src = " + src.getClass().getName()); + } + + public static Buffer putb(Buffer dest, byte v) { + if (dest instanceof ByteBuffer) { + return ((ByteBuffer) dest).put(v); + } else if (dest instanceof ShortBuffer) { + return ((ShortBuffer) dest).put((short) v); + } else if (dest instanceof IntBuffer) { + return ((IntBuffer) dest).put((int) v); + } else { + throw new RuntimeException("Byte doesn't match Buffer Class: " + dest); + } + } + + public static Buffer puts(Buffer dest, short v) { + if (dest instanceof ShortBuffer) { + return ((ShortBuffer) dest).put(v); + } else if (dest instanceof IntBuffer) { + return ((IntBuffer) dest).put((int) v); + } else { + throw new RuntimeException("Short doesn't match Buffer Class: " + dest); + } + } + + public static void puti(Buffer dest, int v) { + if (dest instanceof IntBuffer) { + ((IntBuffer) dest).put(v); + } else { + throw new RuntimeException("Integer doesn't match Buffer Class: " + dest); + } + } + + public static void putf(Buffer dest, float v) { + if (dest instanceof FloatBuffer) { + ((FloatBuffer) dest).put(v); +/* TODO FixedPoint required + } else if (dest instanceof IntBuffer) { + ((IntBuffer) dest).put(FixedPoint.toFixed(v)); +*/ + } else { + throw new RuntimeException("Float doesn't match Buffer Class: " + dest); + } + } + public static void putd(Buffer dest, double v) { + if (dest instanceof FloatBuffer) { + ((FloatBuffer) dest).put((float) v); + } else { + throw new RuntimeException("Double doesn't match Buffer Class: " + dest); + } + } + + public static void rangeCheck(byte[] array, int offset, int minElementsRemaining) { + if (array == null) { + return; + } + + if (array.length < offset + minElementsRemaining) { + throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); + } + } + + public static void rangeCheck(char[] array, int offset, int minElementsRemaining) { + if (array == null) { + return; + } + + if (array.length < offset + minElementsRemaining) { + throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); + } + } + + public static void rangeCheck(short[] array, int offset, int minElementsRemaining) { + if (array == null) { + return; + } + + if (array.length < offset + minElementsRemaining) { + throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); + } + } + + public static void rangeCheck(int[] array, int offset, int minElementsRemaining) { + if (array == null) { + return; + } + + if (array.length < offset + minElementsRemaining) { + throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); + } + } + + public static void rangeCheck(long[] array, int offset, int minElementsRemaining) { + if (array == null) { + return; + } + + if (array.length < offset + minElementsRemaining) { + throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); + } + } + + public static void rangeCheck(float[] array, int offset, int minElementsRemaining) { + if (array == null) { + return; + } + + if (array.length < offset + minElementsRemaining) { + throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); + } + } + + public static void rangeCheck(double[] array, int offset, int minElementsRemaining) { + if (array == null) { + return; + } + + if (array.length < offset + minElementsRemaining) { + throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); + } + } + + public static void rangeCheck(Buffer buffer, int minElementsRemaining) { + if (buffer == null) { + return; + } + + if (buffer.remaining() < minElementsRemaining) { + throw new IndexOutOfBoundsException("Required " + minElementsRemaining + " remaining elements in buffer, only had " + buffer.remaining()); + } + } + + public static void rangeCheckBytes(Object buffer, int minBytesRemaining) { + if (buffer == null) { + return; + } + + int bytesRemaining = 0; + if (buffer instanceof Buffer) { + int elementsRemaining = ((Buffer) buffer).remaining(); + if (buffer instanceof ByteBuffer) { + bytesRemaining = elementsRemaining; + } else if (buffer instanceof FloatBuffer) { + bytesRemaining = elementsRemaining * SIZEOF_FLOAT; + } else if (buffer instanceof IntBuffer) { + bytesRemaining = elementsRemaining * SIZEOF_INT; + } else if (buffer instanceof ShortBuffer) { + bytesRemaining = elementsRemaining * SIZEOF_SHORT; + }else if(Platform.isJavaSE()) { + if (buffer instanceof DoubleBuffer) { + bytesRemaining = elementsRemaining * SIZEOF_DOUBLE; + } else if (buffer instanceof LongBuffer) { + bytesRemaining = elementsRemaining * SIZEOF_LONG; + } else if (buffer instanceof CharBuffer) { + bytesRemaining = elementsRemaining * SIZEOF_CHAR; + } + } + } else if (buffer instanceof Int64Buffer) { + Int64Buffer int64Buffer = (Int64Buffer) buffer; + bytesRemaining = int64Buffer.remaining() * Int64Buffer.elementSize(); + } else if (buffer instanceof PointerBuffer) { + PointerBuffer pointerBuffer = (PointerBuffer) buffer; + bytesRemaining = pointerBuffer.remaining() * PointerBuffer.elementSize(); + } + if (bytesRemaining < minBytesRemaining) { + throw new IndexOutOfBoundsException("Required " + minBytesRemaining + " remaining bytes in buffer, only had " + bytesRemaining); + } + } + +} diff --git a/src/java/com/jogamp/common/nio/Int64Buffer.java b/src/java/com/jogamp/common/nio/Int64Buffer.java new file mode 100644 index 0000000..d1fafb6 --- /dev/null +++ b/src/java/com/jogamp/common/nio/Int64Buffer.java @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2010, Michael Bien + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Michael Bien nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Michael Bien BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.jogamp.common.nio; + +import com.jogamp.common.os.Platform; +import java.nio.ByteBuffer; + +/** + * Hardware independent container for native int64_t arrays. + * + * The native values (NIO direct ByteBuffer) are always 64bit wide. + * + * @author Michael Bien + * @author Sven Gothel + */ +public abstract class Int64Buffer implements NativeBuffer/**/ { + + protected final ByteBuffer bb; + protected int capacity; + protected int position; + protected long[] backup; + + protected Int64Buffer(ByteBuffer bb) { + this.bb = bb; + } + + public static Int64Buffer allocate(int size) { + if (Platform.isJavaSE()) { + return new Int64BufferSE(ByteBuffer.wrap(new byte[elementSize() * size])); + } else { + return new Int64BufferME_CDC_FP(ByteBuffer.wrap(new byte[elementSize() * size])); + } + } + + public static Int64Buffer allocateDirect(int size) { + if (Platform.isJavaSE()) { + return new Int64BufferSE(Buffers.newDirectByteBuffer(elementSize() * size)); + } else { + return new Int64BufferME_CDC_FP(Buffers.newDirectByteBuffer(elementSize() * size)); + } + } + + public static Int64Buffer wrap(ByteBuffer src) { + Int64Buffer res; + if (Platform.isJavaSE()) { + res = new Int64BufferSE(src); + } else { + res = new Int64BufferME_CDC_FP(src); + } + res.updateBackup(); + return res; + + } + + void updateBackup() { + for (int i = 0; i < capacity; i++) { + backup[i] = get(i); + } + } + + int arrayOffset() { + return 0; + } + + public static int elementSize() { + return Buffers.SIZEOF_LONG; + } + + public int limit() { + return capacity; + } + + public int capacity() { + return capacity; + } + + public int position() { + return position; + } + + public Int64Buffer position(int newPos) { + if (0 > newPos || newPos >= capacity) { + throw new IndexOutOfBoundsException("Sorry to interrupt, but the position "+newPos+" was out of bounds. " + + "My capacity is "+capacity()+"."); + } + position = newPos; + return this; + } + + public int remaining() { + return capacity - position; + } + + public boolean hasRemaining() { + return position < capacity; + } + + public Int64Buffer rewind() { + position = 0; + return this; + } + + boolean hasArray() { + return true; + } + + public long[] array() { + return backup; + } + + public ByteBuffer getBuffer() { + return bb; + } + + public boolean isDirect() { + return bb.isDirect(); + } + + public long get() { + long r = get(position); + position++; + return r; + } + + public abstract long get(int idx); + + public abstract Int64Buffer put(int index, long value); + + public abstract Int64Buffer put(long value); + + public Int64Buffer put(Int64Buffer src) { + if (remaining() < src.remaining()) { + throw new IndexOutOfBoundsException(); + } + while (src.hasRemaining()) { + put(src.get()); + } + return this; + } + + public String toString() { + return "Int64Buffer[capacity "+capacity+", position "+position+", elementSize "+elementSize()+", ByteBuffer.capacity "+bb.capacity()+"]"; + } + +} diff --git a/src/java/com/jogamp/common/nio/Int64BufferME_CDC_FP.java b/src/java/com/jogamp/common/nio/Int64BufferME_CDC_FP.java new file mode 100755 index 0000000..5cad3ef --- /dev/null +++ b/src/java/com/jogamp/common/nio/Int64BufferME_CDC_FP.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ +package com.jogamp.common.nio; + +import com.jogamp.common.os.Platform; +import java.nio.*; + +/** + * @author Sven Gothel + * @author Michael Bien + */ +final class Int64BufferME_CDC_FP extends Int64Buffer { + + private IntBuffer pb; + + Int64BufferME_CDC_FP(ByteBuffer bb) { + super(bb); + this.pb = bb.asIntBuffer(); + + capacity = bb.capacity() / elementSize(); + + position = 0; + backup = new long[capacity]; + } + + public long get(int idx) { + if (0 > idx || idx >= capacity) { + throw new IndexOutOfBoundsException(); + } + idx = idx << 1; // 8-byte to 4-byte offset + long lo = 0x00000000FFFFFFFFL & ((long) pb.get(idx)); + long hi = 0x00000000FFFFFFFFL & ((long) pb.get(idx + 1)); + if (Platform.isLittleEndian()) { + return hi << 32 | lo; + } + return lo << 32 | hi; + } + + public Int64Buffer put(int idx, long v) { + if (0 > idx || idx >= capacity) { + throw new IndexOutOfBoundsException(); + } + backup[idx] = v; + idx = idx << 1; // 8-byte to 4-byte offset + int lo = (int) ((v) & 0x00000000FFFFFFFFL); + int hi = (int) ((v >> 32) & 0x00000000FFFFFFFFL); + if (Platform.isLittleEndian()) { + pb.put(idx, lo); + pb.put(idx + 1, hi); + } else { + pb.put(idx, hi); + pb.put(idx + 1, lo); + } + return this; + } + + public Int64Buffer put(long v) { + put(position, v); + position++; + return this; + } +} diff --git a/src/java/com/jogamp/common/nio/Int64BufferSE.java b/src/java/com/jogamp/common/nio/Int64BufferSE.java new file mode 100755 index 0000000..7387320 --- /dev/null +++ b/src/java/com/jogamp/common/nio/Int64BufferSE.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ +package com.jogamp.common.nio; + +import java.nio.*; + +/** + * @author Sven Gothel + * @author Michael Bien + */ +final class Int64BufferSE extends Int64Buffer { + + private LongBuffer pb; + + Int64BufferSE(ByteBuffer bb) { + super(bb); + + this.pb = bb.asLongBuffer(); + + capacity = bb.capacity() / elementSize(); + + position = 0; + backup = new long[capacity]; + } + + public long get(int idx) { + if (0 > idx || idx >= capacity) { + throw new IndexOutOfBoundsException(); + } + return pb.get(idx); + } + + public Int64Buffer put(int idx, long v) { + if (0 > idx || idx >= capacity) { + throw new IndexOutOfBoundsException(); + } + backup[idx] = v; + pb.put(idx, v); + return this; + } + + public Int64Buffer put(long v) { + put(position, v); + position++; + return this; + } +} diff --git a/src/java/com/jogamp/common/nio/NativeBuffer.java b/src/java/com/jogamp/common/nio/NativeBuffer.java new file mode 100644 index 0000000..170297a --- /dev/null +++ b/src/java/com/jogamp/common/nio/NativeBuffer.java @@ -0,0 +1,47 @@ +/* + * Created on Tuesday, March 30 2010 18:22 + */ +package com.jogamp.common.nio; + +import java.nio.ByteBuffer; + +/** + * Hardware independent container for various kinds of buffers. + * + * @author Michael Bien + * @author Sven Gothel + */ +/*public*/ interface NativeBuffer/**/ { // make public as soon we support generics + + public boolean hasRemaining(); + + public boolean isDirect(); + + public int limit(); + + public int position(); + + public int remaining(); + + public long[] array(); + + public int capacity(); +/* + public B rewind(); + + public B position(int newPos); + + public B put(int index, long value); + + public B put(long value); + + public B put(B src); +*/ + public long get(); + + public long get(int idx); + + public ByteBuffer getBuffer(); + + +} diff --git a/src/java/com/jogamp/common/nio/PointerBuffer.java b/src/java/com/jogamp/common/nio/PointerBuffer.java new file mode 100644 index 0000000..9b7232f --- /dev/null +++ b/src/java/com/jogamp/common/nio/PointerBuffer.java @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2010, Michael Bien + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Michael Bien nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Michael Bien BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Created on Saturday, March 27 2010 11:55 + */ +package com.jogamp.common.nio; + +import com.jogamp.common.os.NativeLibrary; +import com.jogamp.common.os.Platform; +import java.nio.ByteBuffer; +import java.nio.Buffer; +import java.util.HashMap; + +/** + * Hardware independent container for native pointer arrays. + * + * The native values (NIO direct ByteBuffer) might be 32bit or 64bit wide, + * depending of the CPU pointer width. + * + * @author Michael Bien + * @author Sven Gothel + */ +public abstract class PointerBuffer implements NativeBuffer/**/ { + + protected final ByteBuffer bb; + protected int capacity; + protected int position; + protected long[] backup; + + protected HashMap/**/ dataMap = new HashMap(); + + static { + NativeLibrary.ensureNativeLibLoaded(); + } + + protected PointerBuffer(ByteBuffer bb) { + this.bb = bb; + } + + public static PointerBuffer allocate(int size) { + if (Platform.isJavaSE()) { + return new PointerBufferSE(ByteBuffer.wrap(new byte[elementSize() * size])); + } else { + return new PointerBufferME_CDC_FP(ByteBuffer.wrap(new byte[elementSize() * size])); + } + } + + public static PointerBuffer allocateDirect(int size) { + if (Platform.isJavaSE()) { + return new PointerBufferSE(Buffers.newDirectByteBuffer(elementSize() * size)); + } else { + return new PointerBufferME_CDC_FP(Buffers.newDirectByteBuffer(elementSize() * size)); + } + } + + public static PointerBuffer wrap(ByteBuffer src) { + PointerBuffer res; + if (Platform.isJavaSE()) { + res = new PointerBufferSE(src); + } else { + res = new PointerBufferME_CDC_FP(src); + } + res.updateBackup(); + return res; + + } + + void updateBackup() { + for (int i = 0; i < capacity; i++) { + backup[i] = get(i); + } + } + + int arrayOffset() { + return 0; + } + + public static int elementSize() { + return Platform.is32Bit() ? Buffers.SIZEOF_INT : Buffers.SIZEOF_LONG; + } + + public int limit() { + return capacity; + } + + public int capacity() { + return capacity; + } + + public int position() { + return position; + } + + public PointerBuffer position(int newPos) { + if (0 > newPos || newPos >= capacity) { + throw new IndexOutOfBoundsException("Sorry to interrupt, but the position "+newPos+" was out of bounds. " + + "My capacity is "+capacity()+"."); + } + position = newPos; + return this; + } + + public int remaining() { + return capacity - position; + } + + public boolean hasRemaining() { + return position < capacity; + } + + public PointerBuffer rewind() { + position = 0; + return this; + } + + boolean hasArray() { + return true; + } + + public long[] array() { + return backup; + } + + public ByteBuffer getBuffer() { + return bb; + } + + public boolean isDirect() { + return bb.isDirect(); + } + + public long get() { + long r = get(position); + position++; + return r; + } + + public abstract long get(int idx); + + /** put the pointer value at position index */ + public abstract PointerBuffer put(int index, long value); + + /** put the pointer value at the end */ + public abstract PointerBuffer put(long value); + + /** Put the address of the given direct Buffer at the given position + of this pointer array. + Adding a reference of the given direct Buffer to this object. */ + public PointerBuffer referenceBuffer(int index, Buffer bb) { + if(null==bb) { + throw new RuntimeException("Buffer is null"); + } + if(!bb.isDirect()) { + throw new RuntimeException("Buffer is not direct"); + } + long bbAddr = getDirectBufferAddressImpl(bb); + if(0==bbAddr) { + throw new RuntimeException("Couldn't determine native address of given Buffer: "+bb); + } + + put(index, bbAddr); + dataMap.put(new Long(bbAddr), bb); + return this; + } + + /** Put the address of the given direct Buffer at the end + of this pointer array. + Adding a reference of the given direct Buffer to this object. */ + public PointerBuffer referenceBuffer(Buffer bb) { + referenceBuffer(position, bb); + position++; + return this; + } + + public Buffer getReferencedBuffer(int index) { + long addr = get(index); + return (Buffer) dataMap.get(new Long(addr)); + } + + public Buffer getReferencedBuffer() { + Buffer bb = getReferencedBuffer(position); + position++; + return bb; + } + + private native long getDirectBufferAddressImpl(Object directBuffer); + + public PointerBuffer put(PointerBuffer src) { + if (remaining() < src.remaining()) { + throw new IndexOutOfBoundsException(); + } + while (src.hasRemaining()) { + put(src.get()); + } + return this; + } + + public String toString() { + return "PointerBuffer[capacity "+capacity+", position "+position+", elementSize "+elementSize()+", ByteBuffer.capacity "+bb.capacity()+"]"; + } + +} diff --git a/src/java/com/jogamp/common/nio/PointerBufferME_CDC_FP.java b/src/java/com/jogamp/common/nio/PointerBufferME_CDC_FP.java new file mode 100755 index 0000000..74c049b --- /dev/null +++ b/src/java/com/jogamp/common/nio/PointerBufferME_CDC_FP.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ +package com.jogamp.common.nio; + +import com.jogamp.common.os.Platform; +import java.nio.*; + +/** + * @author Sven Gothel + * @author Michael Bien + */ +final class PointerBufferME_CDC_FP extends PointerBuffer { + + private IntBuffer pb; + + PointerBufferME_CDC_FP(ByteBuffer bb) { + super(bb); + this.pb = bb.asIntBuffer(); + + capacity = bb.capacity() / elementSize(); + + position = 0; + backup = new long[capacity]; + } + + public long get(int idx) { + if (0 > idx || idx >= capacity) { + throw new IndexOutOfBoundsException(); + } + if (Platform.is32Bit()) { + return pb.get(idx); + } else { + idx = idx << 1; // 8-byte to 4-byte offset + long lo = 0x00000000FFFFFFFFL & ((long) pb.get(idx)); + long hi = 0x00000000FFFFFFFFL & ((long) pb.get(idx + 1)); + if (Platform.isLittleEndian()) { + return hi << 32 | lo; + } + return lo << 32 | hi; + } + } + + public PointerBuffer put(int idx, long v) { + if (0 > idx || idx >= capacity) { + throw new IndexOutOfBoundsException(); + } + backup[idx] = v; + if (Platform.is32Bit()) { + pb.put(idx, (int) v); + } else { + idx = idx << 1; // 8-byte to 4-byte offset + int lo = (int) ((v) & 0x00000000FFFFFFFFL); + int hi = (int) ((v >> 32) & 0x00000000FFFFFFFFL); + if (Platform.isLittleEndian()) { + pb.put(idx, lo); + pb.put(idx + 1, hi); + } else { + pb.put(idx, hi); + pb.put(idx + 1, lo); + } + } + return this; + } + + public PointerBuffer put(long v) { + put(position, v); + position++; + return this; + } +} diff --git a/src/java/com/jogamp/common/nio/PointerBufferSE.java b/src/java/com/jogamp/common/nio/PointerBufferSE.java new file mode 100755 index 0000000..f750430 --- /dev/null +++ b/src/java/com/jogamp/common/nio/PointerBufferSE.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ +package com.jogamp.common.nio; + +import com.jogamp.common.os.Platform; +import java.nio.*; + +/** + * @author Sven Gothel + * @author Michael Bien + */ +final class PointerBufferSE extends PointerBuffer { + + private Buffer pb; + + PointerBufferSE(ByteBuffer bb) { + super(bb); + + if (Platform.is32Bit()) { + this.pb = bb.asIntBuffer(); + } else { + this.pb = bb.asLongBuffer(); + } + + capacity = bb.capacity() / elementSize(); + + position = 0; + backup = new long[capacity]; + } + + public long get(int idx) { + if (0 > idx || idx >= capacity) { + throw new IndexOutOfBoundsException(); + } + if (Platform.is32Bit()) { + return ((IntBuffer) pb).get(idx); + } else { + return ((LongBuffer) pb).get(idx); + } + } + + public PointerBuffer put(int idx, long v) { + if (0 > idx || idx >= capacity) { + throw new IndexOutOfBoundsException(); + } + backup[idx] = v; + if (Platform.is32Bit()) { + ((IntBuffer) pb).put(idx, (int) v); + } else { + ((LongBuffer) pb).put(idx, v); + } + return this; + } + + public PointerBuffer put(long v) { + put(position, v); + position++; + return this; + } +} diff --git a/src/java/com/jogamp/common/nio/StructAccessor.java b/src/java/com/jogamp/common/nio/StructAccessor.java new file mode 100644 index 0000000..117e8de --- /dev/null +++ b/src/java/com/jogamp/common/nio/StructAccessor.java @@ -0,0 +1,327 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ +package com.jogamp.common.nio; + +import com.jogamp.common.os.Platform; +import java.nio.*; + +/** + * @author Kenneth Russel + * @author Michael Bien + */ +public class StructAccessor { + + private ByteBuffer bb; + private FloatBuffer fb; + private IntBuffer ib; + private ShortBuffer sb; + + //Java SE only + private CharBuffer cb; + private DoubleBuffer db; + private LongBuffer lb; + + public StructAccessor(ByteBuffer bb) { + // Setting of byte order is concession to native code which needs + // to instantiate these + if(Platform.isJavaSE()) { + this.bb = bb.order(ByteOrder.nativeOrder()); + }else{ + // JSR 239 does not support the ByteOrder class or the order methods. + // The initial order of a byte buffer is the platform byte order. + this.bb = bb; + } + } + + public ByteBuffer getBuffer() { + return bb; + } + + /** + * Returns a slice of the current ByteBuffer starting at the + * specified byte offset and extending the specified number of + * bytes. Note that this method is not thread-safe with respect to + * the other methods in this class. + */ + public ByteBuffer slice(int byteOffset, int byteLength) { + bb.position(byteOffset); + bb.limit(byteOffset + byteLength); + ByteBuffer newBuf = bb.slice(); + bb.position(0); + bb.limit(bb.capacity()); + return newBuf; + } + + /** Retrieves the byte at the specified slot (byte offset). */ + public byte getByteAt(int slot) { + return bb.get(slot); + } + + /** Puts a byte at the specified slot (byte offset). */ + public void setByteAt(int slot, byte v) { + bb.put(slot, v); + } + + /** Retrieves the char at the specified slot (2-byte offset). */ + public char getCharAt(int slot) { + return charBuffer().get(slot); + } + + /** Puts a char at the specified slot (2-byte offset). */ + public void setCharAt(int slot, char v) { + charBuffer().put(slot, v); + } + + /** Retrieves the double at the specified slot (8-byte offset). */ + public double getDoubleAt(int slot) { + return doubleBuffer().get(slot); + } + + /** Puts a double at the specified slot (8-byte offset). */ + public void setDoubleAt(int slot, double v) { + doubleBuffer().put(slot, v); + } + + /** Retrieves the float at the specified slot (4-byte offset). */ + public float getFloatAt(int slot) { + return floatBuffer().get(slot); + } + + /** Puts a float at the specified slot (4-byte offset). */ + public void setFloatAt(int slot, float v) { + floatBuffer().put(slot, v); + } + + /** Retrieves the int at the specified slot (4-byte offset). */ + public int getIntAt(int slot) { + return intBuffer().get(slot); + } + + /** Puts a int at the specified slot (4-byte offset). */ + public void setIntAt(int slot, int v) { + intBuffer().put(slot, v); + } + + /** Retrieves the short at the specified slot (2-byte offset). */ + public short getShortAt(int slot) { + return shortBuffer().get(slot); + } + + /** Puts a short at the specified slot (2-byte offset). */ + public void setShortAt(int slot, short v) { + shortBuffer().put(slot, v); + } + + public void setBytesAt(int slot, byte[] v) { + for (int i = 0; i < v.length; i++) { + bb.put(slot++, v[i]); + } + } + + public byte[] getBytesAt(int slot, byte[] v) { + for (int i = 0; i < v.length; i++) { + v[i] = bb.get(slot++); + } + return v; + } + + public void setCharsAt(int slot, char[] v) { + for (int i = 0; i < v.length; i++) { + charBuffer().put(slot++, v[i]); + } + } + + public char[] getCharsAt(int slot, char[] v) { + for (int i = 0; i < v.length; i++) { + v[i] = charBuffer().get(slot++); + } + return v; + } + + public void setIntsAt(int slot, int[] v) { + for (int i = 0; i < v.length; i++) { + intBuffer().put(slot++, v[i]); + } + } + + public int[] getIntsAt(int slot, int[] v) { + for (int i = 0; i < v.length; i++) { + v[i] = intBuffer().get(slot++); + } + return v; + } + + public void setFloatsAt(int slot, float[] v) { + for (int i = 0; i < v.length; i++) { + floatBuffer().put(slot++, v[i]); + } + } + + public float[] getFloatsAt(int slot, float[] v) { + for (int i = 0; i < v.length; i++) { + v[i] = floatBuffer().get(slot++); + } + return v; + } + + /** + * Puts a double at the specified slot (8-byte offset). + * May throw an {@link UnsupportedOperationException} + */ + public void setDoublesAt(int slot, double[] v) { + for (int i = 0; i < v.length; i++) { + doubleBuffer().put(slot++, v[i]); + } + } + + /** + * Retrieves the long at the specified slot (8-byte offset). + * May throw an {@link UnsupportedOperationException} + */ + public double[] getDoublesAt(int slot, double[] v) { + for (int i = 0; i < v.length; i++) { + v[i] = doubleBuffer().get(slot++); + } + return v; + } + + /** + * Retrieves the long at the specified slot (8-byte offset). + */ + public long getLongAt(int slot) { + if(Platform.isJavaSE()){ + return longBuffer().get(slot); + }else{ + return getLongCDCAt(slot); + } + } + + /** + * Puts a long at the specified slot (8-byte offset). + */ + public void setLongAt(int slot, long v) { + if(Platform.isJavaSE()){ + longBuffer().put(slot, v); + }else{ + setLongCDCAt(slot, v); + } + } + + //---------------------------------------------------------------------- + // Internals only below this point + // + + private final long getLongCDCAt(int slot) { + slot = slot << 1; // 8-byte to 4-byte offset + IntBuffer intBuffer = intBuffer(); + long lo = 0x00000000FFFFFFFFL & ((long) intBuffer.get(slot)); + long hi = 0x00000000FFFFFFFFL & ((long) intBuffer.get(slot + 1)); + if (Platform.isLittleEndian()) { + return hi << 32 | lo; + } + return lo << 32 | hi; + } + + private final void setLongCDCAt(int slot, long v) { + slot = slot << 1; // 8-byte to 4-byte offset + IntBuffer intBuffer = intBuffer(); + int lo = (int) ((v) & 0x00000000FFFFFFFFL); + int hi = (int) ((v >> 32) & 0x00000000FFFFFFFFL); + if (Platform.isLittleEndian()) { + intBuffer.put(slot, lo); + intBuffer.put(slot + 1, hi); + } else { + intBuffer.put(slot, hi); + intBuffer.put(slot + 1, lo); + } + } + + private final FloatBuffer floatBuffer() { + if (fb == null) { + fb = bb.asFloatBuffer(); + } + return fb; + } + + private final IntBuffer intBuffer() { + if (ib == null) { + ib = bb.asIntBuffer(); + } + return ib; + } + + private final ShortBuffer shortBuffer() { + if (sb == null) { + sb = bb.asShortBuffer(); + } + return sb; + } + + // - - Java SE only - - + + private final LongBuffer longBuffer() { + checkSE(); + if (lb == null) { + lb = bb.asLongBuffer(); + } + return lb; + } + + private final DoubleBuffer doubleBuffer() { + checkSE(); + if (db == null) { + db = bb.asDoubleBuffer(); + } + return db; + } + + private final CharBuffer charBuffer() { + checkSE(); + if (cb == null) { + cb = bb.asCharBuffer(); + } + return cb; + } + + private static void checkSE() { + if (!Platform.isJavaSE()) { + throw new UnsupportedOperationException("I am affraid, this Operation is not supportet on this platform."); + } + } +} diff --git a/src/java/com/jogamp/common/os/DynamicLinker.java b/src/java/com/jogamp/common/os/DynamicLinker.java new file mode 100755 index 0000000..ef5d5dc --- /dev/null +++ b/src/java/com/jogamp/common/os/DynamicLinker.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.common.os; + +/** Provides an abstract interface to the OS's low-level dynamic + linking functionality. */ + +interface DynamicLinker { + public long openLibraryGlobal(String pathname, boolean debug); + public long openLibraryLocal(String pathname, boolean debug); + public long lookupSymbol(long libraryHandle, String symbolName); + public void closeLibrary(long libraryHandle); +} diff --git a/src/java/com/jogamp/common/os/DynamicLookupHelper.java b/src/java/com/jogamp/common/os/DynamicLookupHelper.java new file mode 100755 index 0000000..a4f74a4 --- /dev/null +++ b/src/java/com/jogamp/common/os/DynamicLookupHelper.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.common.os; + +/** Interface callers may use to use the ProcAddressHelper's {@link + ProcAddressHelper#resetProcAddressTable resetProcAddressTable} + helper method to install function pointers into a + ProcAddressTable. This must typically be written with native + code. */ + +public interface DynamicLookupHelper { + /** + * Try to fetch the function pointer for function 'funcName'. + */ + public long dynamicLookupFunction(String funcName); +} diff --git a/src/java/com/jogamp/common/os/MacOSXDynamicLinkerImpl.java b/src/java/com/jogamp/common/os/MacOSXDynamicLinkerImpl.java new file mode 100755 index 0000000..531bc5c --- /dev/null +++ b/src/java/com/jogamp/common/os/MacOSXDynamicLinkerImpl.java @@ -0,0 +1,58 @@ +/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Mon Jul 31 16:27:00 PDT 2006 ----! */ + +package com.jogamp.common.os; + + +public class MacOSXDynamicLinkerImpl implements DynamicLinker { + + public static final int RTLD_LAZY = 0x1; + public static final int RTLD_NOW = 0x2; + public static final int RTLD_LOCAL = 0x4; + public static final int RTLD_GLOBAL = 0x8; + + /** Interface to C language function:
int dlclose(void * __handle); */ + private static native int dlclose(long __handle); + + /** Interface to C language function:
char * dlerror(void); */ + private static native java.lang.String dlerror(); + + /** Interface to C language function:
void * dlopen(const char * __path, int __mode); */ + private static native long dlopen(java.lang.String __path, int __mode); + + /** Interface to C language function:
void * dlsym(void * __handle, const char * __symbol); */ + private static native long dlsym(long __handle, java.lang.String __symbol); + + + // --- Begin CustomJavaCode .cfg declarations + public long openLibraryLocal(String pathname, boolean debug) { + // Note we use RTLD_LOCAL visibility to _NOT_ allow this functionality to + // be used to pre-resolve dependent libraries of JNI code without + // requiring that all references to symbols in those libraries be + // looked up dynamically via the ProcAddressTable mechanism; in + // other words, one can actually link against the library instead of + // having to dlsym all entry points. System.loadLibrary() uses + // RTLD_LOCAL visibility so can't be used for this purpose. + return dlopen(pathname, RTLD_LAZY | RTLD_LOCAL); + } + + public long openLibraryGlobal(String pathname, boolean debug) { + // Note we use RTLD_GLOBAL visibility to allow this functionality to + // be used to pre-resolve dependent libraries of JNI code without + // requiring that all references to symbols in those libraries be + // looked up dynamically via the ProcAddressTable mechanism; in + // other words, one can actually link against the library instead of + // having to dlsym all entry points. System.loadLibrary() uses + // RTLD_LOCAL visibility so can't be used for this purpose. + return dlopen(pathname, RTLD_LAZY | RTLD_GLOBAL); + } + + public long lookupSymbol(long libraryHandle, String symbolName) { + return dlsym(libraryHandle, symbolName); + } + + public void closeLibrary(long libraryHandle) { + dlclose(libraryHandle); + } + // ---- End CustomJavaCode .cfg declarations + +} // end of class MacOSXDynamicLinkerImpl diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java new file mode 100755 index 0000000..2de8bc9 --- /dev/null +++ b/src/java/com/jogamp/common/os/NativeLibrary.java @@ -0,0 +1,426 @@ +/* + * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.common.os; + +import com.jogamp.gluegen.runtime.NativeLibLoader; +import java.io.*; +import java.lang.reflect.*; +import java.security.*; +import java.util.*; + +/** Provides low-level, relatively platform-independent access to + shared ("native") libraries. The core library routines + System.load() and System.loadLibrary() + in general provide suitable functionality for applications using + native code, but are not flexible enough to support certain kinds + of glue code generation and deployment strategies. This class + supports direct linking of native libraries to other shared + objects not necessarily installed on the system (in particular, + via the use of dlopen(RTLD_GLOBAL) on Unix platforms) as well as + manual lookup of function names to support e.g. GlueGen's + ProcAddressTable glue code generation style without additional + supporting code needed in the generated library. */ + +public class NativeLibrary implements DynamicLookupHelper { + private static final int WINDOWS = 1; + private static final int UNIX = 2; + private static final int MACOSX = 3; + private static boolean DEBUG; + private static int platform; + private static DynamicLinker dynLink; + private static String[] prefixes; + private static String[] suffixes; + + static { + // Determine platform we're running on + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String osName = System.getProperty("os.name").toLowerCase(); + if (osName.startsWith("wind")) { + platform = WINDOWS; + } else if (osName.startsWith("mac os x")) { + platform = MACOSX; + } else { + platform = UNIX; + } + + DEBUG = (System.getProperty("gluegen.debug.NativeLibrary") != null); + + return null; + } + }); + // Instantiate dynamic linker implementation + switch (platform) { + case WINDOWS: + dynLink = new WindowsDynamicLinkerImpl(); + prefixes = new String[] { "" }; + suffixes = new String[] { ".dll" }; + break; + case UNIX: + dynLink = new UnixDynamicLinkerImpl(); + prefixes = new String[] { "lib" }; + suffixes = new String[] { ".so" }; + break; + case MACOSX: + dynLink = new MacOSXDynamicLinkerImpl(); + prefixes = new String[] { "lib", "" }; + suffixes = new String[] { ".dylib", ".jnilib", "" }; + break; + default: + throw new InternalError("Platform not initialized properly"); + } + } + + // Platform-specific representation for the handle to the open + // library. This is an HMODULE on Windows and a void* (the result of + // a dlopen() call) on Unix and Mac OS X platforms. + private long libraryHandle; + + // May as well keep around the path to the library we opened + private String libraryPath; + + // Private constructor to prevent arbitrary instances from floating around + private NativeLibrary(long libraryHandle, String libraryPath) { + this.libraryHandle = libraryHandle; + this.libraryPath = libraryPath; + } + + /** Opens the given native library, assuming it has the same base + name on all platforms, looking first in the system's search + path, and in the context of the specified ClassLoader, which is + used to help find the library in the case of e.g. Java Web Start. */ + public static NativeLibrary open(String libName, ClassLoader loader) { + return open(libName, libName, libName, true, loader, true); + } + + /** Opens the given native library, assuming it has the same base + name on all platforms, looking first in the system's search + path, and in the context of the specified ClassLoader, which is + used to help find the library in the case of e.g. Java Web Start. */ + public static NativeLibrary open(String libName, ClassLoader loader, boolean global) { + return open(libName, libName, libName, true, loader, global); + } + + /** Opens the given native library, assuming it has the given base + names (no "lib" prefix or ".dll/.so/.dylib" suffix) on the + Windows, Unix and Mac OS X platforms, respectively, and in the + context of the specified ClassLoader, which is used to help find + the library in the case of e.g. Java Web Start. The + searchSystemPathFirst argument changes the behavior to first + search the default system path rather than searching it last. + Note that we do not currently handle DSO versioning on Unix. + Experience with JOAL and OpenAL has shown that it is extremely + problematic to rely on a specific .so version (for one thing, + ClassLoader.findLibrary on Unix doesn't work with files not + ending in .so, for example .so.0), and in general if this + dynamic loading facility is used correctly the version number + will be irrelevant. + */ + public static NativeLibrary open(String windowsLibName, + String unixLibName, + String macOSXLibName, + boolean searchSystemPathFirst, + ClassLoader loader) { + return open(windowsLibName, unixLibName, macOSXLibName, searchSystemPathFirst, loader, true); + } + + public static NativeLibrary open(String windowsLibName, + String unixLibName, + String macOSXLibName, + boolean searchSystemPathFirst, + ClassLoader loader, boolean global) { + List possiblePaths = enumerateLibraryPaths(windowsLibName, + unixLibName, + macOSXLibName, + searchSystemPathFirst, + loader); + // Iterate down these and see which one if any we can actually find. + for (Iterator iter = possiblePaths.iterator(); iter.hasNext(); ) { + String path = (String) iter.next(); + if (DEBUG) { + System.out.println("Trying to load " + path); + } + ensureNativeLibLoaded(); + long res; + if(global) { + res = dynLink.openLibraryGlobal(path, DEBUG); + } else { + res = dynLink.openLibraryLocal(path, DEBUG); + } + if (res != 0) { + if (DEBUG) { + System.out.println("Successfully loaded " + path + ": res = 0x" + Long.toHexString(res)); + } + return new NativeLibrary(res, path); + } + } + + if (DEBUG) { + System.out.println("Did not succeed in loading (" + windowsLibName + ", " + unixLibName + ", " + macOSXLibName + ")"); + } + + // For now, just return null to indicate the open operation didn't + // succeed (could also throw an exception if we could tell which + // of the openLibrary operations actually failed) + return null; + } + + /** Looks up the given function name in this native library. */ + public long dynamicLookupFunction(String funcName) { + if (libraryHandle == 0) + throw new RuntimeException("Library is not open"); + return dynLink.lookupSymbol(libraryHandle, funcName); + } + + /** Retrieves the low-level library handle from this NativeLibrary + object. On the Windows platform this is an HMODULE, and on Unix + and Mac OS X platforms the void* result of calling dlopen(). */ + public long getLibraryHandle() { + return libraryHandle; + } + + /** Retrieves the path under which this library was opened. */ + public String getLibraryPath() { + return libraryPath; + } + + /** Closes this native library. Further lookup operations are not + allowed after calling this method. */ + public void close() { + if (libraryHandle == 0) + throw new RuntimeException("Library already closed"); + long handle = libraryHandle; + libraryHandle = 0; + dynLink.closeLibrary(handle); + } + + /** Given the base library names (no prefixes/suffixes) for the + various platforms, enumerate the possible locations and names of + the indicated native library on the system. */ + private static List enumerateLibraryPaths(String windowsLibName, + String unixLibName, + String macOSXLibName, + boolean searchSystemPathFirst, + ClassLoader loader) { + List paths = new ArrayList(); + String libName = selectName(windowsLibName, unixLibName, macOSXLibName); + if (libName == null) + return paths; + + // Allow user's full path specification to override our building of paths + File file = new File(libName); + if (file.isAbsolute()) { + paths.add(libName); + return paths; + } + + String[] baseNames = buildNames(libName); + + if (searchSystemPathFirst) { + // Add just the library names to use the OS's search algorithm + for (int i = 0; i < baseNames.length; i++) { + paths.add(baseNames[i]); + } + } + + // The idea to ask the ClassLoader to find the library is borrowed + // from the LWJGL library + String clPath = getPathFromClassLoader(libName, loader); + if (DEBUG) { + System.out.println("Class loader path to " + libName + ": " + clPath); + } + if (clPath != null) { + paths.add(clPath); + } + + // Add entries from java.library.path + String javaLibraryPath = + (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return System.getProperty("java.library.path"); + } + }); + if (javaLibraryPath != null) { + StringTokenizer tokenizer = new StringTokenizer(javaLibraryPath, File.pathSeparator); + while (tokenizer.hasMoreTokens()) { + addPaths(tokenizer.nextToken(), baseNames, paths); + } + } + + // Add current working directory + String userDir = + (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return System.getProperty("user.dir"); + } + }); + addPaths(userDir, baseNames, paths); + + // Add probable Mac OS X-specific paths + if (platform == MACOSX) { + // Add historical location + addPaths("/Library/Frameworks/" + libName + ".Framework", baseNames, paths); + // Add current location + addPaths("/System/Library/Frameworks/" + libName + ".Framework", baseNames, paths); + } + + if (!searchSystemPathFirst) { + // Add just the library names to use the OS's search algorithm + for (int i = 0; i < baseNames.length; i++) { + paths.add(baseNames[i]); + } + } + + return paths; + } + + + private static String selectName(String windowsLibName, + String unixLibName, + String macOSXLibName) { + switch (platform) { + case WINDOWS: + return windowsLibName; + case UNIX: + return unixLibName; + case MACOSX: + return macOSXLibName; + default: + throw new InternalError(); + } + } + + private static String[] buildNames(String libName) { + // If the library name already has the prefix / suffix added + // (principally because we want to force a version number on Unix + // operating systems) then just return the library name. + if (libName.startsWith(prefixes[0])) { + if (libName.endsWith(suffixes[0])) { + return new String[] { libName }; + } + + int idx = libName.indexOf(suffixes[0]); + boolean ok = true; + if (idx >= 0) { + // Check to see if everything after it is a Unix version number + for (int i = idx + suffixes[0].length(); + i < libName.length(); + i++) { + char c = libName.charAt(i); + if (!(c == '.' || (c >= '0' && c <= '9'))) { + ok = false; + break; + } + } + if (ok) { + return new String[] { libName }; + } + } + } + + String[] res = new String[prefixes.length * suffixes.length]; + int idx = 0; + for (int i = 0; i < prefixes.length; i++) { + for (int j = 0; j < suffixes.length; j++) { + res[idx++] = prefixes[i] + libName + suffixes[j]; + } + } + return res; + } + + private static void addPaths(String path, String[] baseNames, List paths) { + for (int j = 0; j < baseNames.length; j++) { + paths.add(path + File.separator + baseNames[j]); + } + } + + private static boolean initializedFindLibraryMethod = false; + private static Method findLibraryMethod = null; + private static String getPathFromClassLoader(final String libName, final ClassLoader loader) { + if (loader == null) + return null; + if (!initializedFindLibraryMethod) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + findLibraryMethod = ClassLoader.class.getDeclaredMethod("findLibrary", + new Class[] { String.class }); + findLibraryMethod.setAccessible(true); + } catch (Exception e) { + // Fail silently disabling this functionality + } + initializedFindLibraryMethod = true; + return null; + } + }); + } + if (findLibraryMethod != null) { + try { + return (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + return findLibraryMethod.invoke(loader, new Object[] { libName }); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + } catch (Exception e) { + if (DEBUG) { + e.printStackTrace(); + } + // Fail silently and continue with other search algorithms + } + } + return null; + } + + private static volatile boolean loadedDynLinkNativeLib; + public static void ensureNativeLibLoaded() { + if (!loadedDynLinkNativeLib) { + synchronized (NativeLibrary.class) { + if (!loadedDynLinkNativeLib) { + loadedDynLinkNativeLib = true; + NativeLibLoader.loadGlueGenRT(); + } + } + } + } +} diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java new file mode 100644 index 0000000..169af13 --- /dev/null +++ b/src/java/com/jogamp/common/os/Platform.java @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2010, Michael Bien, Sven Gothel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Michael Bien nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Michael Bien BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Created on Sunday, March 28 2010 14:43 + */ +package com.jogamp.common.os; + +import com.jogamp.common.nio.Buffers; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; + +/** + * Utility class for querying platform specific properties. + * @author Michael Bien, Sven Gothel + */ +public class Platform { + + public static final boolean JAVA_SE; + public static final boolean LITTLE_ENDIAN; + + private final static boolean is32Bit; + private final static int pointerSizeInBits; + private final static String os, arch; + + static { + NativeLibrary.ensureNativeLibLoaded(); + + // We don't seem to need an AccessController.doPrivileged() block + // here as these system properties are visible even to unsigned + // applets + os = System.getProperty("os.name"); + arch = System.getProperty("os.arch"); + + pointerSizeInBits = getPointerSizeInBitsImpl(); + + // Try to use Sun's sun.arch.data.model first .. + if ( 32 == pointerSizeInBits || 64 == pointerSizeInBits ) { + is32Bit = ( 32 == pointerSizeInBits ); + }else { + String os_lc = os.toLowerCase(); + String arch_lc = arch.toLowerCase(); + + if ((os_lc.startsWith("windows") && arch_lc.equals("x86")) || + (os_lc.startsWith("windows") && arch_lc.equals("arm")) || + (os_lc.startsWith("linux") && arch_lc.equals("i386")) || + (os_lc.startsWith("linux") && arch_lc.equals("x86")) || + (os_lc.startsWith("mac os_lc") && arch_lc.equals("ppc")) || + (os_lc.startsWith("mac os_lc") && arch_lc.equals("i386")) || + (os_lc.startsWith("darwin") && arch_lc.equals("ppc")) || + (os_lc.startsWith("darwin") && arch_lc.equals("i386")) || + (os_lc.startsWith("sunos_lc") && arch_lc.equals("sparc")) || + (os_lc.startsWith("sunos_lc") && arch_lc.equals("x86")) || + (os_lc.startsWith("freebsd") && arch_lc.equals("i386")) || + (os_lc.startsWith("hp-ux") && arch_lc.equals("pa_risc2.0"))) { + is32Bit = true; + } else if ((os_lc.startsWith("windows") && arch_lc.equals("amd64")) || + (os_lc.startsWith("linux") && arch_lc.equals("amd64")) || + (os_lc.startsWith("linux") && arch_lc.equals("x86_64")) || + (os_lc.startsWith("linux") && arch_lc.equals("ia64")) || + (os_lc.startsWith("mac os_lc") && arch_lc.equals("x86_64")) || + (os_lc.startsWith("darwin") && arch_lc.equals("x86_64")) || + (os_lc.startsWith("sunos_lc") && arch_lc.equals("sparcv9")) || + (os_lc.startsWith("sunos_lc") && arch_lc.equals("amd64"))) { + is32Bit = false; + }else{ + throw new RuntimeException("Please port CPU detection (32/64 bit) to your platform (" + os_lc + "/" + arch_lc + ")"); + } + } + + // fast path + boolean se = System.getProperty("java.runtime.name").indexOf("Java SE") != -1; + + if(!se) { + try{ + Class.forName("java.nio.LongBuffer"); + Class.forName("java.nio.DoubleBuffer"); + se = true; + }catch(ClassNotFoundException ex) { + se = false; + } + } + JAVA_SE = se; + + // byte order + ByteBuffer tst_b = Buffers.newDirectByteBuffer(Buffers.SIZEOF_INT); // 32bit in native order + IntBuffer tst_i = tst_b.asIntBuffer(); + ShortBuffer tst_s = tst_b.asShortBuffer(); + tst_i.put(0, 0x0A0B0C0D); + LITTLE_ENDIAN = 0x0C0D == tst_s.get(0); + } + + private Platform() {} + + private static native int getPointerSizeInBitsImpl(); + + /** + * Returns true only if this program is running on the Java Standard Edition. + */ + public static boolean isJavaSE() { + return JAVA_SE; + } + + /** + * Returns true only if this system uses little endian byte ordering. + */ + public static boolean isLittleEndian() { + return LITTLE_ENDIAN; + } + + /** + * Returns the OS name. + */ + public static String getOS() { + return os; + } + + /** + * Returns the CPU architecture String. + */ + public static String getArch() { + return arch; + } + + /** + * Returns true if this JVM is a 32bit JVM. + */ + public static boolean is32Bit() { + return is32Bit; + } + + public static int getPointerSizeInBits() { + return pointerSizeInBits; + } + +} + + diff --git a/src/java/com/jogamp/common/os/UnixDynamicLinkerImpl.java b/src/java/com/jogamp/common/os/UnixDynamicLinkerImpl.java new file mode 100755 index 0000000..02bc828 --- /dev/null +++ b/src/java/com/jogamp/common/os/UnixDynamicLinkerImpl.java @@ -0,0 +1,64 @@ +/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Mon Jul 31 16:26:59 PDT 2006 ----! */ + +package com.jogamp.common.os; + + +public class UnixDynamicLinkerImpl implements DynamicLinker { + + public static final int RTLD_LAZY = 0x00001; + public static final int RTLD_NOW = 0x00002; + public static final int RTLD_NOLOAD = 0x00004; + public static final int RTLD_GLOBAL = 0x00100; + public static final int RTLD_LOCAL = 0x00000; + public static final int RTLD_PARENT = 0x00200; + public static final int RTLD_GROUP = 0x00400; + public static final int RTLD_WORLD = 0x00800; + public static final int RTLD_NODELETE = 0x01000; + public static final int RTLD_FIRST = 0x02000; + + /** Interface to C language function:
int dlclose(void * ); */ + private static native int dlclose(long arg0); + + /** Interface to C language function:
char * dlerror(void); */ + private static native java.lang.String dlerror(); + + /** Interface to C language function:
void * dlopen(const char * , int); */ + private static native long dlopen(java.lang.String arg0, int arg1); + + /** Interface to C language function:
void * dlsym(void * , const char * ); */ + private static native long dlsym(long arg0, java.lang.String arg1); + + + // --- Begin CustomJavaCode .cfg declarations + public long openLibraryLocal(String pathname, boolean debug) { + // Note we use RTLD_GLOBAL visibility to _NOT_ allow this functionality to + // be used to pre-resolve dependent libraries of JNI code without + // requiring that all references to symbols in those libraries be + // looked up dynamically via the ProcAddressTable mechanism; in + // other words, one can actually link against the library instead of + // having to dlsym all entry points. System.loadLibrary() uses + // RTLD_LOCAL visibility so can't be used for this purpose. + return dlopen(pathname, RTLD_LAZY | RTLD_LOCAL); + } + + public long openLibraryGlobal(String pathname, boolean debug) { + // Note we use RTLD_GLOBAL visibility to allow this functionality to + // be used to pre-resolve dependent libraries of JNI code without + // requiring that all references to symbols in those libraries be + // looked up dynamically via the ProcAddressTable mechanism; in + // other words, one can actually link against the library instead of + // having to dlsym all entry points. System.loadLibrary() uses + // RTLD_LOCAL visibility so can't be used for this purpose. + return dlopen(pathname, RTLD_LAZY | RTLD_GLOBAL); + } + + public long lookupSymbol(long libraryHandle, String symbolName) { + return dlsym(libraryHandle, symbolName); + } + + public void closeLibrary(long libraryHandle) { + dlclose(libraryHandle); + } + // ---- End CustomJavaCode .cfg declarations + +} // end of class UnixDynamicLinkerImpl diff --git a/src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java b/src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java new file mode 100755 index 0000000..f5a3312 --- /dev/null +++ b/src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java @@ -0,0 +1,47 @@ +/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Tue May 27 02:37:55 PDT 2008 ----! */ + +package com.jogamp.common.os; + + +public class WindowsDynamicLinkerImpl implements DynamicLinker { + + + /** Interface to C language function:
BOOL FreeLibrary(HANDLE hLibModule); */ + private static native int FreeLibrary(long hLibModule); + + /** Interface to C language function:
DWORD GetLastError(void); */ + private static native int GetLastError(); + + /** Interface to C language function:
PROC GetProcAddressA(HANDLE hModule, LPCSTR lpProcName); */ + private static native long GetProcAddressA(long hModule, java.lang.String lpProcName); + + /** Interface to C language function:
HANDLE LoadLibraryW(LPCWSTR lpLibFileName); */ + private static native long LoadLibraryW(java.lang.String lpLibFileName); + + + // --- Begin CustomJavaCode .cfg declarations + public long openLibraryLocal(String libraryName, boolean debug) { + // How does that work under Windows ? + // Don't know .. so it's an alias for the time being + return openLibraryGlobal(libraryName, debug); + } + + public long openLibraryGlobal(String libraryName, boolean debug) { + long handle = LoadLibraryW(libraryName); + if(0==handle && debug) { + int err = GetLastError(); + System.err.println("LoadLibraryW \""+libraryName+"\" failed, error code: 0x"+Integer.toHexString(err)+", "+err); + } + return handle; + } + + public long lookupSymbol(long libraryHandle, String symbolName) { + return GetProcAddressA(libraryHandle, symbolName); + } + + public void closeLibrary(long libraryHandle) { + FreeLibrary(libraryHandle); + } + // ---- End CustomJavaCode .cfg declarations + +} // end of class WindowsDynamicLinkerImpl diff --git a/src/java/com/jogamp/gluegen/runtime/Buffers.java b/src/java/com/jogamp/gluegen/runtime/Buffers.java deleted file mode 100755 index 49f6e8b..0000000 --- a/src/java/com/jogamp/gluegen/runtime/Buffers.java +++ /dev/null @@ -1,706 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ -package com.jogamp.gluegen.runtime; - -import java.nio.*; - -/** - * @author Kenneth Russel - * @author Sven Gothel - * @author Michael Bien - */ -public class Buffers { - - public static final int SIZEOF_BYTE = 1; - public static final int SIZEOF_SHORT = 2; - public static final int SIZEOF_CHAR = 2; - public static final int SIZEOF_INT = 4; - public static final int SIZEOF_FLOAT = 4; - public static final int SIZEOF_LONG = 8; - public static final int SIZEOF_DOUBLE = 8; - - protected Buffers() {} - - /** - * Allocates a new direct ByteBuffer with the specified number of - * elements. The returned buffer will have its byte order set to - * the host platform's native byte order. - */ - public static ByteBuffer newDirectByteBuffer(int numElements) { - return nativeOrder(ByteBuffer.allocateDirect(numElements)); - } - - public static ByteBuffer newDirectByteBuffer(byte[] values, int offset, int lenght) { - return (ByteBuffer)newDirectByteBuffer(lenght).put(values, offset, lenght).rewind(); - } - - public static ByteBuffer newDirectByteBuffer(byte[] values, int offset) { - return newDirectByteBuffer(values, offset, values.length-offset); - } - - public static ByteBuffer newDirectByteBuffer(byte[] values) { - return newDirectByteBuffer(values, 0); - } - - /** - * Allocates a new direct DoubleBuffer with the specified number of - * elements. The returned buffer will have its byte order set to - * the host platform's native byte order. - */ - public static DoubleBuffer newDirectDoubleBuffer(int numElements) { - return newDirectByteBuffer(numElements * SIZEOF_DOUBLE).asDoubleBuffer(); - } - - public static DoubleBuffer newDirectDoubleBuffer(double[] values, int offset, int lenght) { - return (DoubleBuffer)newDirectDoubleBuffer(lenght).put(values, offset, lenght).rewind(); - } - - public static DoubleBuffer newDirectDoubleBuffer(double[] values, int offset) { - return newDirectDoubleBuffer(values, offset, values.length - offset); - } - - public static DoubleBuffer newDirectDoubleBuffer(double[] values) { - return newDirectDoubleBuffer(values, 0); - } - - /** - * Allocates a new direct FloatBuffer with the specified number of - * elements. The returned buffer will have its byte order set to - * the host platform's native byte order. - */ - public static FloatBuffer newDirectFloatBuffer(int numElements) { - return newDirectByteBuffer(numElements * SIZEOF_FLOAT).asFloatBuffer(); - } - - public static FloatBuffer newDirectFloatBuffer(float[] values, int offset, int lenght) { - return (FloatBuffer)newDirectFloatBuffer(lenght).put(values, offset, lenght).rewind(); - } - - public static FloatBuffer newDirectFloatBuffer(float[] values, int offset) { - return newDirectFloatBuffer(values, offset, values.length - offset); - } - - public static FloatBuffer newDirectFloatBuffer(float[] values) { - return newDirectFloatBuffer(values, 0); - } - - /** - * Allocates a new direct IntBuffer with the specified number of - * elements. The returned buffer will have its byte order set to - * the host platform's native byte order. - */ - public static IntBuffer newDirectIntBuffer(int numElements) { - return newDirectByteBuffer(numElements * SIZEOF_INT).asIntBuffer(); - } - - public static IntBuffer newDirectIntBuffer(int[] values, int offset, int lenght) { - return (IntBuffer)newDirectIntBuffer(lenght).put(values, offset, lenght).rewind(); - } - - public static IntBuffer newDirectIntBuffer(int[] values, int offset) { - return newDirectIntBuffer(values, offset, values.length - offset); - } - - public static IntBuffer newDirectIntBuffer(int[] values) { - return newDirectIntBuffer(values, 0); - } - - /** - * Allocates a new direct LongBuffer with the specified number of - * elements. The returned buffer will have its byte order set to - * the host platform's native byte order. - */ - public static LongBuffer newDirectLongBuffer(int numElements) { - return newDirectByteBuffer(numElements * SIZEOF_LONG).asLongBuffer(); - } - - public static LongBuffer newDirectLongBuffer(long[] values, int offset, int lenght) { - return (LongBuffer)newDirectLongBuffer(lenght).put(values, offset, lenght).rewind(); - } - - public static LongBuffer newDirectLongBuffer(long[] values, int offset) { - return newDirectLongBuffer(values, offset, values.length - offset); - } - - public static LongBuffer newDirectLongBuffer(long[] values) { - return newDirectLongBuffer(values, 0); - } - - /** - * Allocates a new direct ShortBuffer with the specified number of - * elements. The returned buffer will have its byte order set to - * the host platform's native byte order. - */ - public static ShortBuffer newDirectShortBuffer(int numElements) { - return newDirectByteBuffer(numElements * SIZEOF_SHORT).asShortBuffer(); - } - - public static ShortBuffer newDirectShortBuffer(short[] values, int offset, int lenght) { - return (ShortBuffer)newDirectShortBuffer(lenght).put(values, offset, lenght).rewind(); - } - - public static ShortBuffer newDirectShortBuffer(short[] values, int offset) { - return newDirectShortBuffer(values, offset, values.length - offset); - } - - public static ShortBuffer newDirectShortBuffer(short[] values) { - return newDirectShortBuffer(values, 0); - } - - /** - * Allocates a new direct CharBuffer with the specified number of - * elements. The returned buffer will have its byte order set to - * the host platform's native byte order. - */ - public static CharBuffer newDirectCharBuffer(int numElements) { - return newDirectByteBuffer(numElements * SIZEOF_SHORT).asCharBuffer(); - } - - public static CharBuffer newDirectCharBuffer(char[] values, int offset, int lenght) { - return (CharBuffer)newDirectCharBuffer(lenght).put(values, offset, lenght).rewind(); - } - - public static CharBuffer newDirectCharBuffer(char[] values, int offset) { - return newDirectCharBuffer(values, offset, values.length - offset); - } - - public static CharBuffer newDirectCharBuffer(char[] values) { - return newDirectCharBuffer(values, 0); - } - - /** - * Helper routine to set a ByteBuffer to the native byte order, if - * that operation is supported by the underlying NIO - * implementation. - */ - public static ByteBuffer nativeOrder(ByteBuffer buf) { - if (Platform.isJavaSE()) { - return buf.order(ByteOrder.nativeOrder()); - } else { - // JSR 239 does not support the ByteOrder class or the order methods. - // The initial order of a byte buffer is the platform byte order. - return buf; - } - } - - /** - * Returns the size of a single element of this buffer in bytes. - */ - public static final int sizeOfBufferElem(Buffer buffer) { - if (buffer == null) { - return 0; - } - if (buffer instanceof ByteBuffer) { - return SIZEOF_BYTE; - } else if (buffer instanceof IntBuffer) { - return SIZEOF_INT; - } else if (buffer instanceof ShortBuffer) { - return SIZEOF_SHORT; - } else if (buffer instanceof FloatBuffer) { - return SIZEOF_FLOAT; - } else if (Platform.isJavaSE()) { - if (buffer instanceof DoubleBuffer) { - return SIZEOF_DOUBLE; - } else if (buffer instanceof LongBuffer) { - return SIZEOF_LONG; - } else if (buffer instanceof CharBuffer) { - return SIZEOF_CHAR; - } - } - throw new RuntimeException("Unexpected buffer type " + buffer.getClass().getName()); - } - - /** - * Helper routine to tell whether a buffer is direct or not. Null - * pointers are considered NOT direct. isDirect() should really be - * public in Buffer and not replicated in all subclasses. - */ - public static boolean isDirect(Object buf) { - if (buf == null) { - return true; - } - if (buf instanceof ByteBuffer) { - return ((ByteBuffer) buf).isDirect(); - } else if (buf instanceof FloatBuffer) { - return ((FloatBuffer) buf).isDirect(); - } else if (buf instanceof IntBuffer) { - return ((IntBuffer) buf).isDirect(); - } else if (buf instanceof ShortBuffer) { - return ((ShortBuffer) buf).isDirect(); - } else if (buf instanceof Int64Buffer) { - return ((Int64Buffer) buf).isDirect(); - } else if (buf instanceof PointerBuffer) { - return ((PointerBuffer) buf).isDirect(); - } else if (Platform.isJavaSE()) { - if (buf instanceof DoubleBuffer) { - return ((DoubleBuffer) buf).isDirect(); - } else if (buf instanceof LongBuffer) { - return ((LongBuffer) buf).isDirect(); - }else if (buf instanceof CharBuffer) { - return ((CharBuffer) buf).isDirect(); - } - } - throw new RuntimeException("Unexpected buffer type " + buf.getClass().getName()); - } - - /** - * Helper routine to get the Buffer byte offset by taking into - * account the Buffer position and the underlying type. This is - * the total offset for Direct Buffers. - */ - public static int getDirectBufferByteOffset(Object buf) { - if (buf == null) { - return 0; - } - if (buf instanceof Buffer) { - int pos = ((Buffer) buf).position(); - if (buf instanceof ByteBuffer) { - return pos; - } else if (buf instanceof FloatBuffer) { - return pos * SIZEOF_FLOAT; - } else if (buf instanceof IntBuffer) { - return pos * SIZEOF_INT; - } else if (buf instanceof ShortBuffer) { - return pos * SIZEOF_SHORT; - }else if(Platform.isJavaSE()) { - if (buf instanceof DoubleBuffer) { - return pos * SIZEOF_DOUBLE; - } else if (buf instanceof LongBuffer) { - return pos * SIZEOF_LONG; - } else if (buf instanceof CharBuffer) { - return pos * SIZEOF_CHAR; - } - } - } else if (buf instanceof Int64Buffer) { - Int64Buffer int64Buffer = (Int64Buffer) buf; - return int64Buffer.position() * Int64Buffer.elementSize(); - } else if (buf instanceof PointerBuffer) { - PointerBuffer pointerBuffer = (PointerBuffer) buf; - return pointerBuffer.position() * PointerBuffer.elementSize(); - } - - throw new RuntimeException("Disallowed array backing store type in buffer " + buf.getClass().getName()); - } - - /** - * Helper routine to return the array backing store reference from - * a Buffer object. - */ - public static Object getArray(Object buf) { - if (buf == null) { - return null; - } - if (buf instanceof ByteBuffer) { - return ((ByteBuffer) buf).array(); - } else if (buf instanceof FloatBuffer) { - return ((FloatBuffer) buf).array(); - } else if (buf instanceof IntBuffer) { - return ((IntBuffer) buf).array(); - } else if (buf instanceof ShortBuffer) { - return ((ShortBuffer) buf).array(); - } else if (buf instanceof Int64Buffer) { - return ((Int64Buffer) buf).array(); - } else if (buf instanceof PointerBuffer) { - return ((PointerBuffer) buf).array(); - }else if(Platform.isJavaSE()) { - if (buf instanceof DoubleBuffer) { - return ((DoubleBuffer) buf).array(); - } else if (buf instanceof LongBuffer) { - return ((LongBuffer) buf).array(); - } else if (buf instanceof CharBuffer) { - return ((CharBuffer) buf).array(); - } - } - - throw new RuntimeException("Disallowed array backing store type in buffer " + buf.getClass().getName()); - } - - /** - * Helper routine to get the full byte offset from the beginning of - * the array that is the storage for the indirect Buffer - * object. The array offset also includes the position offset - * within the buffer, in addition to any array offset. - */ - public static int getIndirectBufferByteOffset(Object buf) { - if (buf == null) { - return 0; - } - if (buf instanceof Buffer) { - int pos = ((Buffer) buf).position(); - if (buf instanceof ByteBuffer) { - return (((ByteBuffer) buf).arrayOffset() + pos); - } else if (buf instanceof FloatBuffer) { - return (SIZEOF_FLOAT * (((FloatBuffer) buf).arrayOffset() + pos)); - } else if (buf instanceof IntBuffer) { - return (SIZEOF_INT * (((IntBuffer) buf).arrayOffset() + pos)); - } else if (buf instanceof ShortBuffer) { - return (SIZEOF_SHORT * (((ShortBuffer) buf).arrayOffset() + pos)); - }else if(Platform.isJavaSE()) { - if (buf instanceof DoubleBuffer) { - return (SIZEOF_DOUBLE * (((DoubleBuffer) buf).arrayOffset() + pos)); - } else if (buf instanceof LongBuffer) { - return (SIZEOF_LONG * (((LongBuffer) buf).arrayOffset() + pos)); - } else if (buf instanceof CharBuffer) { - return (SIZEOF_CHAR * (((CharBuffer) buf).arrayOffset() + pos)); - } - } - } else if (buf instanceof Int64Buffer) { - Int64Buffer int64Buffer = (Int64Buffer) buf; - return Int64Buffer.elementSize() * (int64Buffer.arrayOffset() + int64Buffer.position()); - } else if (buf instanceof PointerBuffer) { - PointerBuffer pointerBuffer = (PointerBuffer) buf; - return PointerBuffer.elementSize() * (pointerBuffer.arrayOffset() + pointerBuffer.position()); - } - - throw new RuntimeException("Unknown buffer type " + buf.getClass().getName()); - } - - - //---------------------------------------------------------------------- - // Copy routines (type-to-type) - // - /** - * Copies the remaining elements (as defined by - * limit() - position()) in the passed ByteBuffer into - * a newly-allocated direct ByteBuffer. The returned buffer will - * have its byte order set to the host platform's native byte - * order. The position of the newly-allocated buffer will be zero, - * and the position of the passed buffer is unchanged (though its - * mark is changed). - */ - public static ByteBuffer copyByteBuffer(ByteBuffer orig) { - ByteBuffer dest = newDirectByteBuffer(orig.remaining()); - dest.put(orig); - dest.rewind(); - return dest; - } - - /** - * Copies the remaining elements (as defined by - * limit() - position()) in the passed FloatBuffer - * into a newly-allocated direct FloatBuffer. The returned buffer - * will have its byte order set to the host platform's native byte - * order. The position of the newly-allocated buffer will be zero, - * and the position of the passed buffer is unchanged (though its - * mark is changed). - */ - public static FloatBuffer copyFloatBuffer(FloatBuffer orig) { - return copyFloatBufferAsByteBuffer(orig).asFloatBuffer(); - } - - /** - * Copies the remaining elements (as defined by - * limit() - position()) in the passed IntBuffer - * into a newly-allocated direct IntBuffer. The returned buffer - * will have its byte order set to the host platform's native byte - * order. The position of the newly-allocated buffer will be zero, - * and the position of the passed buffer is unchanged (though its - * mark is changed). - */ - public static IntBuffer copyIntBuffer(IntBuffer orig) { - return copyIntBufferAsByteBuffer(orig).asIntBuffer(); - } - - /** - * Copies the remaining elements (as defined by - * limit() - position()) in the passed ShortBuffer - * into a newly-allocated direct ShortBuffer. The returned buffer - * will have its byte order set to the host platform's native byte - * order. The position of the newly-allocated buffer will be zero, - * and the position of the passed buffer is unchanged (though its - * mark is changed). - */ - public static ShortBuffer copyShortBuffer(ShortBuffer orig) { - return copyShortBufferAsByteBuffer(orig).asShortBuffer(); - } - - //---------------------------------------------------------------------- - // Copy routines (type-to-ByteBuffer) - // - /** - * Copies the remaining elements (as defined by - * limit() - position()) in the passed FloatBuffer - * into a newly-allocated direct ByteBuffer. The returned buffer - * will have its byte order set to the host platform's native byte - * order. The position of the newly-allocated buffer will be zero, - * and the position of the passed buffer is unchanged (though its - * mark is changed). - */ - public static ByteBuffer copyFloatBufferAsByteBuffer(FloatBuffer orig) { - ByteBuffer dest = newDirectByteBuffer(orig.remaining() * SIZEOF_FLOAT); - dest.asFloatBuffer().put(orig); - dest.rewind(); - return dest; - } - - /** - * Copies the remaining elements (as defined by - * limit() - position()) in the passed IntBuffer into - * a newly-allocated direct ByteBuffer. The returned buffer will - * have its byte order set to the host platform's native byte - * order. The position of the newly-allocated buffer will be zero, - * and the position of the passed buffer is unchanged (though its - * mark is changed). - */ - public static ByteBuffer copyIntBufferAsByteBuffer(IntBuffer orig) { - ByteBuffer dest = newDirectByteBuffer(orig.remaining() * SIZEOF_INT); - dest.asIntBuffer().put(orig); - dest.rewind(); - return dest; - } - - /** - * Copies the remaining elements (as defined by - * limit() - position()) in the passed ShortBuffer - * into a newly-allocated direct ByteBuffer. The returned buffer - * will have its byte order set to the host platform's native byte - * order. The position of the newly-allocated buffer will be zero, - * and the position of the passed buffer is unchanged (though its - * mark is changed). - */ - public static ByteBuffer copyShortBufferAsByteBuffer(ShortBuffer orig) { - ByteBuffer dest = newDirectByteBuffer(orig.remaining() * SIZEOF_SHORT); - dest.asShortBuffer().put(orig); - dest.rewind(); - return dest; - } - - //---------------------------------------------------------------------- - // Conversion routines - // - public final static FloatBuffer getFloatBuffer(DoubleBuffer source) { - source.rewind(); - FloatBuffer dest = newDirectFloatBuffer(source.limit()); - while (source.hasRemaining()) { - dest.put((float) source.get()); - } - return dest; - } - - //---------------------------------------------------------------------- - // Convenient put methods with generic target Buffer - // - public static Buffer put(Buffer dest, Buffer src) { - if ((dest instanceof ByteBuffer) && (src instanceof ByteBuffer)) { - return ((ByteBuffer) dest).put((ByteBuffer) src); - } else if ((dest instanceof ShortBuffer) && (src instanceof ShortBuffer)) { - return ((ShortBuffer) dest).put((ShortBuffer) src); - } else if ((dest instanceof IntBuffer) && (src instanceof IntBuffer)) { - return ((IntBuffer) dest).put((IntBuffer) src); - } else if ((dest instanceof FloatBuffer) && (src instanceof FloatBuffer)) { - return ((FloatBuffer) dest).put((FloatBuffer) src); - } else if (Platform.isJavaSE()) { - if ((dest instanceof LongBuffer) && (src instanceof LongBuffer)) { - return ((LongBuffer) dest).put((LongBuffer) src); - } else if ((dest instanceof DoubleBuffer) && (src instanceof DoubleBuffer)) { - return ((DoubleBuffer) dest).put((DoubleBuffer) src); - } else if ((dest instanceof CharBuffer) && (src instanceof CharBuffer)) { - return ((CharBuffer) dest).put((CharBuffer) src); - } - } - throw new RuntimeException("Incompatible Buffer classes: dest = " + dest.getClass().getName() + ", src = " + src.getClass().getName()); - } - - public static Buffer putb(Buffer dest, byte v) { - if (dest instanceof ByteBuffer) { - return ((ByteBuffer) dest).put(v); - } else if (dest instanceof ShortBuffer) { - return ((ShortBuffer) dest).put((short) v); - } else if (dest instanceof IntBuffer) { - return ((IntBuffer) dest).put((int) v); - } else { - throw new RuntimeException("Byte doesn't match Buffer Class: " + dest); - } - } - - public static Buffer puts(Buffer dest, short v) { - if (dest instanceof ShortBuffer) { - return ((ShortBuffer) dest).put(v); - } else if (dest instanceof IntBuffer) { - return ((IntBuffer) dest).put((int) v); - } else { - throw new RuntimeException("Short doesn't match Buffer Class: " + dest); - } - } - - public static void puti(Buffer dest, int v) { - if (dest instanceof IntBuffer) { - ((IntBuffer) dest).put(v); - } else { - throw new RuntimeException("Integer doesn't match Buffer Class: " + dest); - } - } - - public static void putf(Buffer dest, float v) { - if (dest instanceof FloatBuffer) { - ((FloatBuffer) dest).put(v); -/* TODO FixedPoint required - } else if (dest instanceof IntBuffer) { - ((IntBuffer) dest).put(FixedPoint.toFixed(v)); -*/ - } else { - throw new RuntimeException("Float doesn't match Buffer Class: " + dest); - } - } - public static void putd(Buffer dest, double v) { - if (dest instanceof FloatBuffer) { - ((FloatBuffer) dest).put((float) v); - } else { - throw new RuntimeException("Double doesn't match Buffer Class: " + dest); - } - } - - public static void rangeCheck(byte[] array, int offset, int minElementsRemaining) { - if (array == null) { - return; - } - - if (array.length < offset + minElementsRemaining) { - throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); - } - } - - public static void rangeCheck(char[] array, int offset, int minElementsRemaining) { - if (array == null) { - return; - } - - if (array.length < offset + minElementsRemaining) { - throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); - } - } - - public static void rangeCheck(short[] array, int offset, int minElementsRemaining) { - if (array == null) { - return; - } - - if (array.length < offset + minElementsRemaining) { - throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); - } - } - - public static void rangeCheck(int[] array, int offset, int minElementsRemaining) { - if (array == null) { - return; - } - - if (array.length < offset + minElementsRemaining) { - throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); - } - } - - public static void rangeCheck(long[] array, int offset, int minElementsRemaining) { - if (array == null) { - return; - } - - if (array.length < offset + minElementsRemaining) { - throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); - } - } - - public static void rangeCheck(float[] array, int offset, int minElementsRemaining) { - if (array == null) { - return; - } - - if (array.length < offset + minElementsRemaining) { - throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); - } - } - - public static void rangeCheck(double[] array, int offset, int minElementsRemaining) { - if (array == null) { - return; - } - - if (array.length < offset + minElementsRemaining) { - throw new ArrayIndexOutOfBoundsException("Required " + minElementsRemaining + " elements in array, only had " + (array.length - offset)); - } - } - - public static void rangeCheck(Buffer buffer, int minElementsRemaining) { - if (buffer == null) { - return; - } - - if (buffer.remaining() < minElementsRemaining) { - throw new IndexOutOfBoundsException("Required " + minElementsRemaining + " remaining elements in buffer, only had " + buffer.remaining()); - } - } - - public static void rangeCheckBytes(Object buffer, int minBytesRemaining) { - if (buffer == null) { - return; - } - - int bytesRemaining = 0; - if (buffer instanceof Buffer) { - int elementsRemaining = ((Buffer) buffer).remaining(); - if (buffer instanceof ByteBuffer) { - bytesRemaining = elementsRemaining; - } else if (buffer instanceof FloatBuffer) { - bytesRemaining = elementsRemaining * SIZEOF_FLOAT; - } else if (buffer instanceof IntBuffer) { - bytesRemaining = elementsRemaining * SIZEOF_INT; - } else if (buffer instanceof ShortBuffer) { - bytesRemaining = elementsRemaining * SIZEOF_SHORT; - }else if(Platform.isJavaSE()) { - if (buffer instanceof DoubleBuffer) { - bytesRemaining = elementsRemaining * SIZEOF_DOUBLE; - } else if (buffer instanceof LongBuffer) { - bytesRemaining = elementsRemaining * SIZEOF_LONG; - } else if (buffer instanceof CharBuffer) { - bytesRemaining = elementsRemaining * SIZEOF_CHAR; - } - } - } else if (buffer instanceof Int64Buffer) { - Int64Buffer int64Buffer = (Int64Buffer) buffer; - bytesRemaining = int64Buffer.remaining() * Int64Buffer.elementSize(); - } else if (buffer instanceof PointerBuffer) { - PointerBuffer pointerBuffer = (PointerBuffer) buffer; - bytesRemaining = pointerBuffer.remaining() * PointerBuffer.elementSize(); - } - if (bytesRemaining < minBytesRemaining) { - throw new IndexOutOfBoundsException("Required " + minBytesRemaining + " remaining bytes in buffer, only had " + bytesRemaining); - } - } - -} diff --git a/src/java/com/jogamp/gluegen/runtime/DynamicLinker.java b/src/java/com/jogamp/gluegen/runtime/DynamicLinker.java deleted file mode 100755 index f3cfcfd..0000000 --- a/src/java/com/jogamp/gluegen/runtime/DynamicLinker.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.runtime; - -/** Provides an abstract interface to the OS's low-level dynamic - linking functionality. */ - -interface DynamicLinker { - public long openLibraryGlobal(String pathname, boolean debug); - public long openLibraryLocal(String pathname, boolean debug); - public long lookupSymbol(long libraryHandle, String symbolName); - public void closeLibrary(long libraryHandle); -} diff --git a/src/java/com/jogamp/gluegen/runtime/DynamicLookupHelper.java b/src/java/com/jogamp/gluegen/runtime/DynamicLookupHelper.java deleted file mode 100755 index bc29732..0000000 --- a/src/java/com/jogamp/gluegen/runtime/DynamicLookupHelper.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.runtime; - -/** Interface callers may use to use the ProcAddressHelper's {@link - ProcAddressHelper#resetProcAddressTable resetProcAddressTable} - helper method to install function pointers into a - ProcAddressTable. This must typically be written with native - code. */ - -public interface DynamicLookupHelper { - /** - * Try to fetch the function pointer for function 'funcName'. - */ - public long dynamicLookupFunction(String funcName); -} diff --git a/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java b/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java deleted file mode 100644 index c110310..0000000 --- a/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2010, Michael Bien - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Michael Bien nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Michael Bien BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package com.jogamp.gluegen.runtime; - -import java.nio.ByteBuffer; - -/** - * Hardware independent container for native int64_t arrays. - * - * The native values (NIO direct ByteBuffer) are always 64bit wide. - * - * @author Michael Bien - * @author Sven Gothel - */ -public abstract class Int64Buffer implements NativeBuffer/**/ { - - protected final ByteBuffer bb; - protected int capacity; - protected int position; - protected long[] backup; - - protected Int64Buffer(ByteBuffer bb) { - this.bb = bb; - } - - public static Int64Buffer allocate(int size) { - if (Platform.isJavaSE()) { - return new Int64BufferSE(ByteBuffer.wrap(new byte[elementSize() * size])); - } else { - return new Int64BufferME_CDC_FP(ByteBuffer.wrap(new byte[elementSize() * size])); - } - } - - public static Int64Buffer allocateDirect(int size) { - if (Platform.isJavaSE()) { - return new Int64BufferSE(Buffers.newDirectByteBuffer(elementSize() * size)); - } else { - return new Int64BufferME_CDC_FP(Buffers.newDirectByteBuffer(elementSize() * size)); - } - } - - public static Int64Buffer wrap(ByteBuffer src) { - Int64Buffer res; - if (Platform.isJavaSE()) { - res = new Int64BufferSE(src); - } else { - res = new Int64BufferME_CDC_FP(src); - } - res.updateBackup(); - return res; - - } - - void updateBackup() { - for (int i = 0; i < capacity; i++) { - backup[i] = get(i); - } - } - - int arrayOffset() { - return 0; - } - - public static int elementSize() { - return Buffers.SIZEOF_LONG; - } - - public int limit() { - return capacity; - } - - public int capacity() { - return capacity; - } - - public int position() { - return position; - } - - public Int64Buffer position(int newPos) { - if (0 > newPos || newPos >= capacity) { - throw new IndexOutOfBoundsException("Sorry to interrupt, but the position "+newPos+" was out of bounds. " + - "My capacity is "+capacity()+"."); - } - position = newPos; - return this; - } - - public int remaining() { - return capacity - position; - } - - public boolean hasRemaining() { - return position < capacity; - } - - public Int64Buffer rewind() { - position = 0; - return this; - } - - boolean hasArray() { - return true; - } - - public long[] array() { - return backup; - } - - public ByteBuffer getBuffer() { - return bb; - } - - public boolean isDirect() { - return bb.isDirect(); - } - - public long get() { - long r = get(position); - position++; - return r; - } - - public abstract long get(int idx); - - public abstract Int64Buffer put(int index, long value); - - public abstract Int64Buffer put(long value); - - public Int64Buffer put(Int64Buffer src) { - if (remaining() < src.remaining()) { - throw new IndexOutOfBoundsException(); - } - while (src.hasRemaining()) { - put(src.get()); - } - return this; - } - - public String toString() { - return "Int64Buffer[capacity "+capacity+", position "+position+", elementSize "+elementSize()+", ByteBuffer.capacity "+bb.capacity()+"]"; - } - -} diff --git a/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java b/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java deleted file mode 100755 index cedb737..0000000 --- a/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - */ -package com.jogamp.gluegen.runtime; - -import java.nio.*; - -/** - * @author Sven Gothel - * @author Michael Bien - */ -final class Int64BufferME_CDC_FP extends Int64Buffer { - - private IntBuffer pb; - - Int64BufferME_CDC_FP(ByteBuffer bb) { - super(bb); - this.pb = bb.asIntBuffer(); - - capacity = bb.capacity() / elementSize(); - - position = 0; - backup = new long[capacity]; - } - - public long get(int idx) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - idx = idx << 1; // 8-byte to 4-byte offset - long lo = 0x00000000FFFFFFFFL & ((long) pb.get(idx)); - long hi = 0x00000000FFFFFFFFL & ((long) pb.get(idx + 1)); - if (Platform.isLittleEndian()) { - return hi << 32 | lo; - } - return lo << 32 | hi; - } - - public Int64Buffer put(int idx, long v) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - backup[idx] = v; - idx = idx << 1; // 8-byte to 4-byte offset - int lo = (int) ((v) & 0x00000000FFFFFFFFL); - int hi = (int) ((v >> 32) & 0x00000000FFFFFFFFL); - if (Platform.isLittleEndian()) { - pb.put(idx, lo); - pb.put(idx + 1, hi); - } else { - pb.put(idx, hi); - pb.put(idx + 1, lo); - } - return this; - } - - public Int64Buffer put(long v) { - put(position, v); - position++; - return this; - } -} diff --git a/src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java b/src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java deleted file mode 100755 index 166d0c6..0000000 --- a/src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - */ -package com.jogamp.gluegen.runtime; - -import java.nio.*; - -/** - * @author Sven Gothel - * @author Michael Bien - */ -final class Int64BufferSE extends Int64Buffer { - - private LongBuffer pb; - - Int64BufferSE(ByteBuffer bb) { - super(bb); - - this.pb = bb.asLongBuffer(); - - capacity = bb.capacity() / elementSize(); - - position = 0; - backup = new long[capacity]; - } - - public long get(int idx) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - return pb.get(idx); - } - - public Int64Buffer put(int idx, long v) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - backup[idx] = v; - pb.put(idx, v); - return this; - } - - public Int64Buffer put(long v) { - put(position, v); - position++; - return this; - } -} diff --git a/src/java/com/jogamp/gluegen/runtime/MacOSXDynamicLinkerImpl.java b/src/java/com/jogamp/gluegen/runtime/MacOSXDynamicLinkerImpl.java deleted file mode 100755 index 8abbd4e..0000000 --- a/src/java/com/jogamp/gluegen/runtime/MacOSXDynamicLinkerImpl.java +++ /dev/null @@ -1,60 +0,0 @@ -/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Mon Jul 31 16:27:00 PDT 2006 ----! */ - -package com.jogamp.gluegen.runtime; - -import com.jogamp.gluegen.runtime.*; - -public class MacOSXDynamicLinkerImpl implements DynamicLinker -{ - - public static final int RTLD_LAZY = 0x1; - public static final int RTLD_NOW = 0x2; - public static final int RTLD_LOCAL = 0x4; - public static final int RTLD_GLOBAL = 0x8; - - /** Interface to C language function:
int dlclose(void * __handle); */ - private static native int dlclose(long __handle); - - /** Interface to C language function:
char * dlerror(void); */ - private static native java.lang.String dlerror(); - - /** Interface to C language function:
void * dlopen(const char * __path, int __mode); */ - private static native long dlopen(java.lang.String __path, int __mode); - - /** Interface to C language function:
void * dlsym(void * __handle, const char * __symbol); */ - private static native long dlsym(long __handle, java.lang.String __symbol); - - - // --- Begin CustomJavaCode .cfg declarations - public long openLibraryLocal(String pathname, boolean debug) { - // Note we use RTLD_LOCAL visibility to _NOT_ allow this functionality to - // be used to pre-resolve dependent libraries of JNI code without - // requiring that all references to symbols in those libraries be - // looked up dynamically via the ProcAddressTable mechanism; in - // other words, one can actually link against the library instead of - // having to dlsym all entry points. System.loadLibrary() uses - // RTLD_LOCAL visibility so can't be used for this purpose. - return dlopen(pathname, RTLD_LAZY | RTLD_LOCAL); - } - - public long openLibraryGlobal(String pathname, boolean debug) { - // Note we use RTLD_GLOBAL visibility to allow this functionality to - // be used to pre-resolve dependent libraries of JNI code without - // requiring that all references to symbols in those libraries be - // looked up dynamically via the ProcAddressTable mechanism; in - // other words, one can actually link against the library instead of - // having to dlsym all entry points. System.loadLibrary() uses - // RTLD_LOCAL visibility so can't be used for this purpose. - return dlopen(pathname, RTLD_LAZY | RTLD_GLOBAL); - } - - public long lookupSymbol(long libraryHandle, String symbolName) { - return dlsym(libraryHandle, symbolName); - } - - public void closeLibrary(long libraryHandle) { - dlclose(libraryHandle); - } - // ---- End CustomJavaCode .cfg declarations - -} // end of class MacOSXDynamicLinkerImpl diff --git a/src/java/com/jogamp/gluegen/runtime/NativeBuffer.java b/src/java/com/jogamp/gluegen/runtime/NativeBuffer.java deleted file mode 100644 index d3587e3..0000000 --- a/src/java/com/jogamp/gluegen/runtime/NativeBuffer.java +++ /dev/null @@ -1,48 +0,0 @@ - -/* - * Created on Tuesday, March 30 2010 18:22 - */ -package com.jogamp.gluegen.runtime; - -import java.nio.ByteBuffer; - -/** - * Hardware independent container for various kinds of buffers. - * - * @author Michael Bien - * @author Sven Gothel - */ -/*public*/ interface NativeBuffer/**/ { // make public as soon we support generics - - public boolean hasRemaining(); - - public boolean isDirect(); - - public int limit(); - - public int position(); - - public int remaining(); - - public long[] array(); - - public int capacity(); -/* - public B rewind(); - - public B position(int newPos); - - public B put(int index, long value); - - public B put(long value); - - public B put(B src); -*/ - public long get(); - - public long get(int idx); - - public ByteBuffer getBuffer(); - - -} diff --git a/src/java/com/jogamp/gluegen/runtime/NativeLibrary.java b/src/java/com/jogamp/gluegen/runtime/NativeLibrary.java deleted file mode 100755 index 7de75a3..0000000 --- a/src/java/com/jogamp/gluegen/runtime/NativeLibrary.java +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ - -package com.jogamp.gluegen.runtime; - -import java.io.*; -import java.lang.reflect.*; -import java.security.*; -import java.util.*; - -/** Provides low-level, relatively platform-independent access to - shared ("native") libraries. The core library routines - System.load() and System.loadLibrary() - in general provide suitable functionality for applications using - native code, but are not flexible enough to support certain kinds - of glue code generation and deployment strategies. This class - supports direct linking of native libraries to other shared - objects not necessarily installed on the system (in particular, - via the use of dlopen(RTLD_GLOBAL) on Unix platforms) as well as - manual lookup of function names to support e.g. GlueGen's - ProcAddressTable glue code generation style without additional - supporting code needed in the generated library. */ - -public class NativeLibrary implements DynamicLookupHelper { - private static final int WINDOWS = 1; - private static final int UNIX = 2; - private static final int MACOSX = 3; - private static boolean DEBUG; - private static int platform; - private static DynamicLinker dynLink; - private static String[] prefixes; - private static String[] suffixes; - - static { - // Determine platform we're running on - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - String osName = System.getProperty("os.name").toLowerCase(); - if (osName.startsWith("wind")) { - platform = WINDOWS; - } else if (osName.startsWith("mac os x")) { - platform = MACOSX; - } else { - platform = UNIX; - } - - DEBUG = (System.getProperty("gluegen.debug.NativeLibrary") != null); - - return null; - } - }); - // Instantiate dynamic linker implementation - switch (platform) { - case WINDOWS: - dynLink = new WindowsDynamicLinkerImpl(); - prefixes = new String[] { "" }; - suffixes = new String[] { ".dll" }; - break; - case UNIX: - dynLink = new UnixDynamicLinkerImpl(); - prefixes = new String[] { "lib" }; - suffixes = new String[] { ".so" }; - break; - case MACOSX: - dynLink = new MacOSXDynamicLinkerImpl(); - prefixes = new String[] { "lib", "" }; - suffixes = new String[] { ".dylib", ".jnilib", "" }; - break; - default: - throw new InternalError("Platform not initialized properly"); - } - } - - // Platform-specific representation for the handle to the open - // library. This is an HMODULE on Windows and a void* (the result of - // a dlopen() call) on Unix and Mac OS X platforms. - private long libraryHandle; - - // May as well keep around the path to the library we opened - private String libraryPath; - - // Private constructor to prevent arbitrary instances from floating around - private NativeLibrary(long libraryHandle, String libraryPath) { - this.libraryHandle = libraryHandle; - this.libraryPath = libraryPath; - } - - /** Opens the given native library, assuming it has the same base - name on all platforms, looking first in the system's search - path, and in the context of the specified ClassLoader, which is - used to help find the library in the case of e.g. Java Web Start. */ - public static NativeLibrary open(String libName, ClassLoader loader) { - return open(libName, libName, libName, true, loader, true); - } - - /** Opens the given native library, assuming it has the same base - name on all platforms, looking first in the system's search - path, and in the context of the specified ClassLoader, which is - used to help find the library in the case of e.g. Java Web Start. */ - public static NativeLibrary open(String libName, ClassLoader loader, boolean global) { - return open(libName, libName, libName, true, loader, global); - } - - /** Opens the given native library, assuming it has the given base - names (no "lib" prefix or ".dll/.so/.dylib" suffix) on the - Windows, Unix and Mac OS X platforms, respectively, and in the - context of the specified ClassLoader, which is used to help find - the library in the case of e.g. Java Web Start. The - searchSystemPathFirst argument changes the behavior to first - search the default system path rather than searching it last. - Note that we do not currently handle DSO versioning on Unix. - Experience with JOAL and OpenAL has shown that it is extremely - problematic to rely on a specific .so version (for one thing, - ClassLoader.findLibrary on Unix doesn't work with files not - ending in .so, for example .so.0), and in general if this - dynamic loading facility is used correctly the version number - will be irrelevant. - */ - public static NativeLibrary open(String windowsLibName, - String unixLibName, - String macOSXLibName, - boolean searchSystemPathFirst, - ClassLoader loader) { - return open(windowsLibName, unixLibName, macOSXLibName, searchSystemPathFirst, loader, true); - } - - public static NativeLibrary open(String windowsLibName, - String unixLibName, - String macOSXLibName, - boolean searchSystemPathFirst, - ClassLoader loader, boolean global) { - List possiblePaths = enumerateLibraryPaths(windowsLibName, - unixLibName, - macOSXLibName, - searchSystemPathFirst, - loader); - // Iterate down these and see which one if any we can actually find. - for (Iterator iter = possiblePaths.iterator(); iter.hasNext(); ) { - String path = (String) iter.next(); - if (DEBUG) { - System.out.println("Trying to load " + path); - } - ensureNativeLibLoaded(); - long res; - if(global) { - res = dynLink.openLibraryGlobal(path, DEBUG); - } else { - res = dynLink.openLibraryLocal(path, DEBUG); - } - if (res != 0) { - if (DEBUG) { - System.out.println("Successfully loaded " + path + ": res = 0x" + Long.toHexString(res)); - } - return new NativeLibrary(res, path); - } - } - - if (DEBUG) { - System.out.println("Did not succeed in loading (" + windowsLibName + ", " + unixLibName + ", " + macOSXLibName + ")"); - } - - // For now, just return null to indicate the open operation didn't - // succeed (could also throw an exception if we could tell which - // of the openLibrary operations actually failed) - return null; - } - - /** Looks up the given function name in this native library. */ - public long dynamicLookupFunction(String funcName) { - if (libraryHandle == 0) - throw new RuntimeException("Library is not open"); - return dynLink.lookupSymbol(libraryHandle, funcName); - } - - /** Retrieves the low-level library handle from this NativeLibrary - object. On the Windows platform this is an HMODULE, and on Unix - and Mac OS X platforms the void* result of calling dlopen(). */ - public long getLibraryHandle() { - return libraryHandle; - } - - /** Retrieves the path under which this library was opened. */ - public String getLibraryPath() { - return libraryPath; - } - - /** Closes this native library. Further lookup operations are not - allowed after calling this method. */ - public void close() { - if (libraryHandle == 0) - throw new RuntimeException("Library already closed"); - long handle = libraryHandle; - libraryHandle = 0; - dynLink.closeLibrary(handle); - } - - /** Given the base library names (no prefixes/suffixes) for the - various platforms, enumerate the possible locations and names of - the indicated native library on the system. */ - private static List enumerateLibraryPaths(String windowsLibName, - String unixLibName, - String macOSXLibName, - boolean searchSystemPathFirst, - ClassLoader loader) { - List paths = new ArrayList(); - String libName = selectName(windowsLibName, unixLibName, macOSXLibName); - if (libName == null) - return paths; - - // Allow user's full path specification to override our building of paths - File file = new File(libName); - if (file.isAbsolute()) { - paths.add(libName); - return paths; - } - - String[] baseNames = buildNames(libName); - - if (searchSystemPathFirst) { - // Add just the library names to use the OS's search algorithm - for (int i = 0; i < baseNames.length; i++) { - paths.add(baseNames[i]); - } - } - - // The idea to ask the ClassLoader to find the library is borrowed - // from the LWJGL library - String clPath = getPathFromClassLoader(libName, loader); - if (DEBUG) { - System.out.println("Class loader path to " + libName + ": " + clPath); - } - if (clPath != null) { - paths.add(clPath); - } - - // Add entries from java.library.path - String javaLibraryPath = - (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty("java.library.path"); - } - }); - if (javaLibraryPath != null) { - StringTokenizer tokenizer = new StringTokenizer(javaLibraryPath, File.pathSeparator); - while (tokenizer.hasMoreTokens()) { - addPaths(tokenizer.nextToken(), baseNames, paths); - } - } - - // Add current working directory - String userDir = - (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty("user.dir"); - } - }); - addPaths(userDir, baseNames, paths); - - // Add probable Mac OS X-specific paths - if (platform == MACOSX) { - // Add historical location - addPaths("/Library/Frameworks/" + libName + ".Framework", baseNames, paths); - // Add current location - addPaths("/System/Library/Frameworks/" + libName + ".Framework", baseNames, paths); - } - - if (!searchSystemPathFirst) { - // Add just the library names to use the OS's search algorithm - for (int i = 0; i < baseNames.length; i++) { - paths.add(baseNames[i]); - } - } - - return paths; - } - - - private static String selectName(String windowsLibName, - String unixLibName, - String macOSXLibName) { - switch (platform) { - case WINDOWS: - return windowsLibName; - case UNIX: - return unixLibName; - case MACOSX: - return macOSXLibName; - default: - throw new InternalError(); - } - } - - private static String[] buildNames(String libName) { - // If the library name already has the prefix / suffix added - // (principally because we want to force a version number on Unix - // operating systems) then just return the library name. - if (libName.startsWith(prefixes[0])) { - if (libName.endsWith(suffixes[0])) { - return new String[] { libName }; - } - - int idx = libName.indexOf(suffixes[0]); - boolean ok = true; - if (idx >= 0) { - // Check to see if everything after it is a Unix version number - for (int i = idx + suffixes[0].length(); - i < libName.length(); - i++) { - char c = libName.charAt(i); - if (!(c == '.' || (c >= '0' && c <= '9'))) { - ok = false; - break; - } - } - if (ok) { - return new String[] { libName }; - } - } - } - - String[] res = new String[prefixes.length * suffixes.length]; - int idx = 0; - for (int i = 0; i < prefixes.length; i++) { - for (int j = 0; j < suffixes.length; j++) { - res[idx++] = prefixes[i] + libName + suffixes[j]; - } - } - return res; - } - - private static void addPaths(String path, String[] baseNames, List paths) { - for (int j = 0; j < baseNames.length; j++) { - paths.add(path + File.separator + baseNames[j]); - } - } - - private static boolean initializedFindLibraryMethod = false; - private static Method findLibraryMethod = null; - private static String getPathFromClassLoader(final String libName, final ClassLoader loader) { - if (loader == null) - return null; - if (!initializedFindLibraryMethod) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - try { - findLibraryMethod = ClassLoader.class.getDeclaredMethod("findLibrary", - new Class[] { String.class }); - findLibraryMethod.setAccessible(true); - } catch (Exception e) { - // Fail silently disabling this functionality - } - initializedFindLibraryMethod = true; - return null; - } - }); - } - if (findLibraryMethod != null) { - try { - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - try { - return findLibraryMethod.invoke(loader, new Object[] { libName }); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }); - } catch (Exception e) { - if (DEBUG) { - e.printStackTrace(); - } - // Fail silently and continue with other search algorithms - } - } - return null; - } - - private static volatile boolean loadedDynLinkNativeLib; - static void ensureNativeLibLoaded() { - if (!loadedDynLinkNativeLib) { - synchronized (NativeLibrary.class) { - if (!loadedDynLinkNativeLib) { - loadedDynLinkNativeLib = true; - NativeLibLoader.loadGlueGenRT(); - } - } - } - } -} diff --git a/src/java/com/jogamp/gluegen/runtime/Platform.java b/src/java/com/jogamp/gluegen/runtime/Platform.java deleted file mode 100644 index a621279..0000000 --- a/src/java/com/jogamp/gluegen/runtime/Platform.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2010, Michael Bien, Sven Gothel - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Michael Bien nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Michael Bien BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Created on Sunday, March 28 2010 14:43 - */ -package com.jogamp.gluegen.runtime; - -import java.nio.ByteBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; - -/** - * Utility class for querying platform specific properties. - * @author Michael Bien, Sven Gothel - */ -public class Platform { - - public static final boolean JAVA_SE; - public static final boolean LITTLE_ENDIAN; - - private final static boolean is32Bit; - private final static int pointerSizeInBits; - private final static String os, arch; - - static { - NativeLibrary.ensureNativeLibLoaded(); - - // We don't seem to need an AccessController.doPrivileged() block - // here as these system properties are visible even to unsigned - // applets - os = System.getProperty("os.name"); - arch = System.getProperty("os.arch"); - - pointerSizeInBits = getPointerSizeInBitsImpl(); - - // Try to use Sun's sun.arch.data.model first .. - if ( 32 == pointerSizeInBits || 64 == pointerSizeInBits ) { - is32Bit = ( 32 == pointerSizeInBits ); - }else { - String os_lc = os.toLowerCase(); - String arch_lc = arch.toLowerCase(); - - if ((os_lc.startsWith("windows") && arch_lc.equals("x86")) || - (os_lc.startsWith("windows") && arch_lc.equals("arm")) || - (os_lc.startsWith("linux") && arch_lc.equals("i386")) || - (os_lc.startsWith("linux") && arch_lc.equals("x86")) || - (os_lc.startsWith("mac os_lc") && arch_lc.equals("ppc")) || - (os_lc.startsWith("mac os_lc") && arch_lc.equals("i386")) || - (os_lc.startsWith("darwin") && arch_lc.equals("ppc")) || - (os_lc.startsWith("darwin") && arch_lc.equals("i386")) || - (os_lc.startsWith("sunos_lc") && arch_lc.equals("sparc")) || - (os_lc.startsWith("sunos_lc") && arch_lc.equals("x86")) || - (os_lc.startsWith("freebsd") && arch_lc.equals("i386")) || - (os_lc.startsWith("hp-ux") && arch_lc.equals("pa_risc2.0"))) { - is32Bit = true; - } else if ((os_lc.startsWith("windows") && arch_lc.equals("amd64")) || - (os_lc.startsWith("linux") && arch_lc.equals("amd64")) || - (os_lc.startsWith("linux") && arch_lc.equals("x86_64")) || - (os_lc.startsWith("linux") && arch_lc.equals("ia64")) || - (os_lc.startsWith("mac os_lc") && arch_lc.equals("x86_64")) || - (os_lc.startsWith("darwin") && arch_lc.equals("x86_64")) || - (os_lc.startsWith("sunos_lc") && arch_lc.equals("sparcv9")) || - (os_lc.startsWith("sunos_lc") && arch_lc.equals("amd64"))) { - is32Bit = false; - }else{ - throw new RuntimeException("Please port CPU detection (32/64 bit) to your platform (" + os_lc + "/" + arch_lc + ")"); - } - } - - // fast path - boolean se = System.getProperty("java.runtime.name").indexOf("Java SE") != -1; - - if(!se) { - try{ - Class.forName("java.nio.LongBuffer"); - Class.forName("java.nio.DoubleBuffer"); - se = true; - }catch(ClassNotFoundException ex) { - se = false; - } - } - JAVA_SE = se; - - // byte order - ByteBuffer tst_b = Buffers.newDirectByteBuffer(Buffers.SIZEOF_INT); // 32bit in native order - IntBuffer tst_i = tst_b.asIntBuffer(); - ShortBuffer tst_s = tst_b.asShortBuffer(); - tst_i.put(0, 0x0A0B0C0D); - LITTLE_ENDIAN = 0x0C0D == tst_s.get(0); - } - - private Platform() {} - - private static native int getPointerSizeInBitsImpl(); - - /** - * Returns true only if this program is running on the Java Standard Edition. - */ - public static boolean isJavaSE() { - return JAVA_SE; - } - - /** - * Returns true only if this system uses little endian byte ordering. - */ - public static boolean isLittleEndian() { - return LITTLE_ENDIAN; - } - - /** - * Returns the OS name. - */ - public static String getOS() { - return os; - } - - /** - * Returns the CPU architecture String. - */ - public static String getArch() { - return arch; - } - - /** - * Returns true if this JVM is a 32bit JVM. - */ - public static boolean is32Bit() { - return is32Bit; - } - - public static int getPointerSizeInBits() { - return pointerSizeInBits; - } - -} - - diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java deleted file mode 100644 index e68fd72..0000000 --- a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (c) 2010, Michael Bien - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Michael Bien nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Michael Bien BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Created on Saturday, March 27 2010 11:55 - */ -package com.jogamp.gluegen.runtime; - -import java.nio.ByteBuffer; -import java.nio.Buffer; -import java.util.HashMap; - -/** - * Hardware independent container for native pointer arrays. - * - * The native values (NIO direct ByteBuffer) might be 32bit or 64bit wide, - * depending of the CPU pointer width. - * - * @author Michael Bien - * @author Sven Gothel - */ -public abstract class PointerBuffer implements NativeBuffer/**/ { - - protected final ByteBuffer bb; - protected int capacity; - protected int position; - protected long[] backup; - - protected HashMap/**/ dataMap = new HashMap(); - - static { - NativeLibrary.ensureNativeLibLoaded(); - } - - protected PointerBuffer(ByteBuffer bb) { - this.bb = bb; - } - - public static PointerBuffer allocate(int size) { - if (Platform.isJavaSE()) { - return new PointerBufferSE(ByteBuffer.wrap(new byte[elementSize() * size])); - } else { - return new PointerBufferME_CDC_FP(ByteBuffer.wrap(new byte[elementSize() * size])); - } - } - - public static PointerBuffer allocateDirect(int size) { - if (Platform.isJavaSE()) { - return new PointerBufferSE(Buffers.newDirectByteBuffer(elementSize() * size)); - } else { - return new PointerBufferME_CDC_FP(Buffers.newDirectByteBuffer(elementSize() * size)); - } - } - - public static PointerBuffer wrap(ByteBuffer src) { - PointerBuffer res; - if (Platform.isJavaSE()) { - res = new PointerBufferSE(src); - } else { - res = new PointerBufferME_CDC_FP(src); - } - res.updateBackup(); - return res; - - } - - void updateBackup() { - for (int i = 0; i < capacity; i++) { - backup[i] = get(i); - } - } - - int arrayOffset() { - return 0; - } - - public static int elementSize() { - return Platform.is32Bit() ? Buffers.SIZEOF_INT : Buffers.SIZEOF_LONG; - } - - public int limit() { - return capacity; - } - - public int capacity() { - return capacity; - } - - public int position() { - return position; - } - - public PointerBuffer position(int newPos) { - if (0 > newPos || newPos >= capacity) { - throw new IndexOutOfBoundsException("Sorry to interrupt, but the position "+newPos+" was out of bounds. " + - "My capacity is "+capacity()+"."); - } - position = newPos; - return this; - } - - public int remaining() { - return capacity - position; - } - - public boolean hasRemaining() { - return position < capacity; - } - - public PointerBuffer rewind() { - position = 0; - return this; - } - - boolean hasArray() { - return true; - } - - public long[] array() { - return backup; - } - - public ByteBuffer getBuffer() { - return bb; - } - - public boolean isDirect() { - return bb.isDirect(); - } - - public long get() { - long r = get(position); - position++; - return r; - } - - public abstract long get(int idx); - - /** put the pointer value at position index */ - public abstract PointerBuffer put(int index, long value); - - /** put the pointer value at the end */ - public abstract PointerBuffer put(long value); - - /** Put the address of the given direct Buffer at the given position - of this pointer array. - Adding a reference of the given direct Buffer to this object. */ - public PointerBuffer referenceBuffer(int index, Buffer bb) { - if(null==bb) { - throw new RuntimeException("Buffer is null"); - } - if(!bb.isDirect()) { - throw new RuntimeException("Buffer is not direct"); - } - long bbAddr = getDirectBufferAddressImpl(bb); - if(0==bbAddr) { - throw new RuntimeException("Couldn't determine native address of given Buffer: "+bb); - } - - put(index, bbAddr); - dataMap.put(new Long(bbAddr), bb); - return this; - } - - /** Put the address of the given direct Buffer at the end - of this pointer array. - Adding a reference of the given direct Buffer to this object. */ - public PointerBuffer referenceBuffer(Buffer bb) { - referenceBuffer(position, bb); - position++; - return this; - } - - public Buffer getReferencedBuffer(int index) { - long addr = get(index); - return (Buffer) dataMap.get(new Long(addr)); - } - - public Buffer getReferencedBuffer() { - Buffer bb = getReferencedBuffer(position); - position++; - return bb; - } - - private native long getDirectBufferAddressImpl(Object directBuffer); - - public PointerBuffer put(PointerBuffer src) { - if (remaining() < src.remaining()) { - throw new IndexOutOfBoundsException(); - } - while (src.hasRemaining()) { - put(src.get()); - } - return this; - } - - public String toString() { - return "PointerBuffer[capacity "+capacity+", position "+position+", elementSize "+elementSize()+", ByteBuffer.capacity "+bb.capacity()+"]"; - } - -} diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java b/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java deleted file mode 100755 index 1134ee7..0000000 --- a/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - */ -package com.jogamp.gluegen.runtime; - -import java.nio.*; - -/** - * @author Sven Gothel - * @author Michael Bien - */ -final class PointerBufferME_CDC_FP extends PointerBuffer { - - private IntBuffer pb; - - PointerBufferME_CDC_FP(ByteBuffer bb) { - super(bb); - this.pb = bb.asIntBuffer(); - - capacity = bb.capacity() / elementSize(); - - position = 0; - backup = new long[capacity]; - } - - public long get(int idx) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - if (Platform.is32Bit()) { - return pb.get(idx); - } else { - idx = idx << 1; // 8-byte to 4-byte offset - long lo = 0x00000000FFFFFFFFL & ((long) pb.get(idx)); - long hi = 0x00000000FFFFFFFFL & ((long) pb.get(idx + 1)); - if (Platform.isLittleEndian()) { - return hi << 32 | lo; - } - return lo << 32 | hi; - } - } - - public PointerBuffer put(int idx, long v) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - backup[idx] = v; - if (Platform.is32Bit()) { - pb.put(idx, (int) v); - } else { - idx = idx << 1; // 8-byte to 4-byte offset - int lo = (int) ((v) & 0x00000000FFFFFFFFL); - int hi = (int) ((v >> 32) & 0x00000000FFFFFFFFL); - if (Platform.isLittleEndian()) { - pb.put(idx, lo); - pb.put(idx + 1, hi); - } else { - pb.put(idx, hi); - pb.put(idx + 1, lo); - } - } - return this; - } - - public PointerBuffer put(long v) { - put(position, v); - position++; - return this; - } -} diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java b/src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java deleted file mode 100755 index 6f131a9..0000000 --- a/src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - */ -package com.jogamp.gluegen.runtime; - -import java.nio.*; - -/** - * @author Sven Gothel - * @author Michael Bien - */ -final class PointerBufferSE extends PointerBuffer { - - private Buffer pb; - - PointerBufferSE(ByteBuffer bb) { - super(bb); - - if (Platform.is32Bit()) { - this.pb = bb.asIntBuffer(); - } else { - this.pb = bb.asLongBuffer(); - } - - capacity = bb.capacity() / elementSize(); - - position = 0; - backup = new long[capacity]; - } - - public long get(int idx) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - if (Platform.is32Bit()) { - return ((IntBuffer) pb).get(idx); - } else { - return ((LongBuffer) pb).get(idx); - } - } - - public PointerBuffer put(int idx, long v) { - if (0 > idx || idx >= capacity) { - throw new IndexOutOfBoundsException(); - } - backup[idx] = v; - if (Platform.is32Bit()) { - ((IntBuffer) pb).put(idx, (int) v); - } else { - ((LongBuffer) pb).put(idx, v); - } - return this; - } - - public PointerBuffer put(long v) { - put(position, v); - position++; - return this; - } -} diff --git a/src/java/com/jogamp/gluegen/runtime/ProcAddressHelper.java b/src/java/com/jogamp/gluegen/runtime/ProcAddressHelper.java index 1b7f9d6..787eab5 100644 --- a/src/java/com/jogamp/gluegen/runtime/ProcAddressHelper.java +++ b/src/java/com/jogamp/gluegen/runtime/ProcAddressHelper.java @@ -39,6 +39,7 @@ package com.jogamp.gluegen.runtime; +import com.jogamp.common.os.DynamicLookupHelper; import java.security.*; // Debugging only diff --git a/src/java/com/jogamp/gluegen/runtime/StructAccessor.java b/src/java/com/jogamp/gluegen/runtime/StructAccessor.java deleted file mode 100644 index 6f3ad7d..0000000 --- a/src/java/com/jogamp/gluegen/runtime/StructAccessor.java +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - * - * Sun gratefully acknowledges that this software was originally authored - * and developed by Kenneth Bradley Russell and Christopher John Kline. - */ -package com.jogamp.gluegen.runtime; - -import java.nio.*; - -/** - * @author Kenneth Russel - * @author Michael Bien - */ -public class StructAccessor { - - private ByteBuffer bb; - private FloatBuffer fb; - private IntBuffer ib; - private ShortBuffer sb; - - //Java SE only - private CharBuffer cb; - private DoubleBuffer db; - private LongBuffer lb; - - public StructAccessor(ByteBuffer bb) { - // Setting of byte order is concession to native code which needs - // to instantiate these - if(Platform.isJavaSE()) { - this.bb = bb.order(ByteOrder.nativeOrder()); - }else{ - // JSR 239 does not support the ByteOrder class or the order methods. - // The initial order of a byte buffer is the platform byte order. - this.bb = bb; - } - } - - public ByteBuffer getBuffer() { - return bb; - } - - /** - * Returns a slice of the current ByteBuffer starting at the - * specified byte offset and extending the specified number of - * bytes. Note that this method is not thread-safe with respect to - * the other methods in this class. - */ - public ByteBuffer slice(int byteOffset, int byteLength) { - bb.position(byteOffset); - bb.limit(byteOffset + byteLength); - ByteBuffer newBuf = bb.slice(); - bb.position(0); - bb.limit(bb.capacity()); - return newBuf; - } - - /** Retrieves the byte at the specified slot (byte offset). */ - public byte getByteAt(int slot) { - return bb.get(slot); - } - - /** Puts a byte at the specified slot (byte offset). */ - public void setByteAt(int slot, byte v) { - bb.put(slot, v); - } - - /** Retrieves the char at the specified slot (2-byte offset). */ - public char getCharAt(int slot) { - return charBuffer().get(slot); - } - - /** Puts a char at the specified slot (2-byte offset). */ - public void setCharAt(int slot, char v) { - charBuffer().put(slot, v); - } - - /** Retrieves the double at the specified slot (8-byte offset). */ - public double getDoubleAt(int slot) { - return doubleBuffer().get(slot); - } - - /** Puts a double at the specified slot (8-byte offset). */ - public void setDoubleAt(int slot, double v) { - doubleBuffer().put(slot, v); - } - - /** Retrieves the float at the specified slot (4-byte offset). */ - public float getFloatAt(int slot) { - return floatBuffer().get(slot); - } - - /** Puts a float at the specified slot (4-byte offset). */ - public void setFloatAt(int slot, float v) { - floatBuffer().put(slot, v); - } - - /** Retrieves the int at the specified slot (4-byte offset). */ - public int getIntAt(int slot) { - return intBuffer().get(slot); - } - - /** Puts a int at the specified slot (4-byte offset). */ - public void setIntAt(int slot, int v) { - intBuffer().put(slot, v); - } - - /** Retrieves the short at the specified slot (2-byte offset). */ - public short getShortAt(int slot) { - return shortBuffer().get(slot); - } - - /** Puts a short at the specified slot (2-byte offset). */ - public void setShortAt(int slot, short v) { - shortBuffer().put(slot, v); - } - - public void setBytesAt(int slot, byte[] v) { - for (int i = 0; i < v.length; i++) { - bb.put(slot++, v[i]); - } - } - - public byte[] getBytesAt(int slot, byte[] v) { - for (int i = 0; i < v.length; i++) { - v[i] = bb.get(slot++); - } - return v; - } - - public void setCharsAt(int slot, char[] v) { - for (int i = 0; i < v.length; i++) { - charBuffer().put(slot++, v[i]); - } - } - - public char[] getCharsAt(int slot, char[] v) { - for (int i = 0; i < v.length; i++) { - v[i] = charBuffer().get(slot++); - } - return v; - } - - public void setIntsAt(int slot, int[] v) { - for (int i = 0; i < v.length; i++) { - intBuffer().put(slot++, v[i]); - } - } - - public int[] getIntsAt(int slot, int[] v) { - for (int i = 0; i < v.length; i++) { - v[i] = intBuffer().get(slot++); - } - return v; - } - - public void setFloatsAt(int slot, float[] v) { - for (int i = 0; i < v.length; i++) { - floatBuffer().put(slot++, v[i]); - } - } - - public float[] getFloatsAt(int slot, float[] v) { - for (int i = 0; i < v.length; i++) { - v[i] = floatBuffer().get(slot++); - } - return v; - } - - /** - * Puts a double at the specified slot (8-byte offset). - * May throw an {@link UnsupportedOperationException} - */ - public void setDoublesAt(int slot, double[] v) { - for (int i = 0; i < v.length; i++) { - doubleBuffer().put(slot++, v[i]); - } - } - - /** - * Retrieves the long at the specified slot (8-byte offset). - * May throw an {@link UnsupportedOperationException} - */ - public double[] getDoublesAt(int slot, double[] v) { - for (int i = 0; i < v.length; i++) { - v[i] = doubleBuffer().get(slot++); - } - return v; - } - - /** - * Retrieves the long at the specified slot (8-byte offset). - */ - public long getLongAt(int slot) { - if(Platform.isJavaSE()){ - return longBuffer().get(slot); - }else{ - return getLongCDCAt(slot); - } - } - - /** - * Puts a long at the specified slot (8-byte offset). - */ - public void setLongAt(int slot, long v) { - if(Platform.isJavaSE()){ - longBuffer().put(slot, v); - }else{ - setLongCDCAt(slot, v); - } - } - - //---------------------------------------------------------------------- - // Internals only below this point - // - - private final long getLongCDCAt(int slot) { - slot = slot << 1; // 8-byte to 4-byte offset - IntBuffer intBuffer = intBuffer(); - long lo = 0x00000000FFFFFFFFL & ((long) intBuffer.get(slot)); - long hi = 0x00000000FFFFFFFFL & ((long) intBuffer.get(slot + 1)); - if (Platform.isLittleEndian()) { - return hi << 32 | lo; - } - return lo << 32 | hi; - } - - private final void setLongCDCAt(int slot, long v) { - slot = slot << 1; // 8-byte to 4-byte offset - IntBuffer intBuffer = intBuffer(); - int lo = (int) ((v) & 0x00000000FFFFFFFFL); - int hi = (int) ((v >> 32) & 0x00000000FFFFFFFFL); - if (Platform.isLittleEndian()) { - intBuffer.put(slot, lo); - intBuffer.put(slot + 1, hi); - } else { - intBuffer.put(slot, hi); - intBuffer.put(slot + 1, lo); - } - } - - private final FloatBuffer floatBuffer() { - if (fb == null) { - fb = bb.asFloatBuffer(); - } - return fb; - } - - private final IntBuffer intBuffer() { - if (ib == null) { - ib = bb.asIntBuffer(); - } - return ib; - } - - private final ShortBuffer shortBuffer() { - if (sb == null) { - sb = bb.asShortBuffer(); - } - return sb; - } - - // - - Java SE only - - - - private final LongBuffer longBuffer() { - checkSE(); - if (lb == null) { - lb = bb.asLongBuffer(); - } - return lb; - } - - private final DoubleBuffer doubleBuffer() { - checkSE(); - if (db == null) { - db = bb.asDoubleBuffer(); - } - return db; - } - - private final CharBuffer charBuffer() { - checkSE(); - if (cb == null) { - cb = bb.asCharBuffer(); - } - return cb; - } - - private static void checkSE() { - if (!Platform.isJavaSE()) { - throw new UnsupportedOperationException("I am affraid, this Operation is not supportet on this platform."); - } - } -} diff --git a/src/java/com/jogamp/gluegen/runtime/UnixDynamicLinkerImpl.java b/src/java/com/jogamp/gluegen/runtime/UnixDynamicLinkerImpl.java deleted file mode 100755 index 018f31b..0000000 --- a/src/java/com/jogamp/gluegen/runtime/UnixDynamicLinkerImpl.java +++ /dev/null @@ -1,66 +0,0 @@ -/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Mon Jul 31 16:26:59 PDT 2006 ----! */ - -package com.jogamp.gluegen.runtime; - -import com.jogamp.gluegen.runtime.*; - -public class UnixDynamicLinkerImpl implements DynamicLinker -{ - - public static final int RTLD_LAZY = 0x00001; - public static final int RTLD_NOW = 0x00002; - public static final int RTLD_NOLOAD = 0x00004; - public static final int RTLD_GLOBAL = 0x00100; - public static final int RTLD_LOCAL = 0x00000; - public static final int RTLD_PARENT = 0x00200; - public static final int RTLD_GROUP = 0x00400; - public static final int RTLD_WORLD = 0x00800; - public static final int RTLD_NODELETE = 0x01000; - public static final int RTLD_FIRST = 0x02000; - - /** Interface to C language function:
int dlclose(void * ); */ - private static native int dlclose(long arg0); - - /** Interface to C language function:
char * dlerror(void); */ - private static native java.lang.String dlerror(); - - /** Interface to C language function:
void * dlopen(const char * , int); */ - private static native long dlopen(java.lang.String arg0, int arg1); - - /** Interface to C language function:
void * dlsym(void * , const char * ); */ - private static native long dlsym(long arg0, java.lang.String arg1); - - - // --- Begin CustomJavaCode .cfg declarations - public long openLibraryLocal(String pathname, boolean debug) { - // Note we use RTLD_GLOBAL visibility to _NOT_ allow this functionality to - // be used to pre-resolve dependent libraries of JNI code without - // requiring that all references to symbols in those libraries be - // looked up dynamically via the ProcAddressTable mechanism; in - // other words, one can actually link against the library instead of - // having to dlsym all entry points. System.loadLibrary() uses - // RTLD_LOCAL visibility so can't be used for this purpose. - return dlopen(pathname, RTLD_LAZY | RTLD_LOCAL); - } - - public long openLibraryGlobal(String pathname, boolean debug) { - // Note we use RTLD_GLOBAL visibility to allow this functionality to - // be used to pre-resolve dependent libraries of JNI code without - // requiring that all references to symbols in those libraries be - // looked up dynamically via the ProcAddressTable mechanism; in - // other words, one can actually link against the library instead of - // having to dlsym all entry points. System.loadLibrary() uses - // RTLD_LOCAL visibility so can't be used for this purpose. - return dlopen(pathname, RTLD_LAZY | RTLD_GLOBAL); - } - - public long lookupSymbol(long libraryHandle, String symbolName) { - return dlsym(libraryHandle, symbolName); - } - - public void closeLibrary(long libraryHandle) { - dlclose(libraryHandle); - } - // ---- End CustomJavaCode .cfg declarations - -} // end of class UnixDynamicLinkerImpl diff --git a/src/java/com/jogamp/gluegen/runtime/WindowsDynamicLinkerImpl.java b/src/java/com/jogamp/gluegen/runtime/WindowsDynamicLinkerImpl.java deleted file mode 100755 index 87b9a37..0000000 --- a/src/java/com/jogamp/gluegen/runtime/WindowsDynamicLinkerImpl.java +++ /dev/null @@ -1,49 +0,0 @@ -/* !---- DO NOT EDIT: This file autogenerated by com\sun\gluegen\JavaEmitter.java on Tue May 27 02:37:55 PDT 2008 ----! */ - -package com.jogamp.gluegen.runtime; - -import com.jogamp.gluegen.runtime.*; - -public class WindowsDynamicLinkerImpl implements DynamicLinker -{ - - - /** Interface to C language function:
BOOL FreeLibrary(HANDLE hLibModule); */ - private static native int FreeLibrary(long hLibModule); - - /** Interface to C language function:
DWORD GetLastError(void); */ - private static native int GetLastError(); - - /** Interface to C language function:
PROC GetProcAddressA(HANDLE hModule, LPCSTR lpProcName); */ - private static native long GetProcAddressA(long hModule, java.lang.String lpProcName); - - /** Interface to C language function:
HANDLE LoadLibraryW(LPCWSTR lpLibFileName); */ - private static native long LoadLibraryW(java.lang.String lpLibFileName); - - - // --- Begin CustomJavaCode .cfg declarations - public long openLibraryLocal(String libraryName, boolean debug) { - // How does that work under Windows ? - // Don't know .. so it's an alias for the time being - return openLibraryGlobal(libraryName, debug); - } - - public long openLibraryGlobal(String libraryName, boolean debug) { - long handle = LoadLibraryW(libraryName); - if(0==handle && debug) { - int err = GetLastError(); - System.err.println("LoadLibraryW \""+libraryName+"\" failed, error code: 0x"+Integer.toHexString(err)+", "+err); - } - return handle; - } - - public long lookupSymbol(long libraryHandle, String symbolName) { - return GetProcAddressA(libraryHandle, symbolName); - } - - public void closeLibrary(long libraryHandle) { - FreeLibrary(libraryHandle); - } - // ---- End CustomJavaCode .cfg declarations - -} // end of class WindowsDynamicLinkerImpl diff --git a/src/java/com/jogamp/gluegen/runtime/opengl/GLProcAddressHelper.java b/src/java/com/jogamp/gluegen/runtime/opengl/GLProcAddressHelper.java index 7470c46..2031d9e 100644 --- a/src/java/com/jogamp/gluegen/runtime/opengl/GLProcAddressHelper.java +++ b/src/java/com/jogamp/gluegen/runtime/opengl/GLProcAddressHelper.java @@ -36,6 +36,7 @@ package com.jogamp.gluegen.runtime.opengl; +import com.jogamp.common.os.DynamicLookupHelper; import com.jogamp.gluegen.runtime.*; // Debugging only diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java index 0703f76..fc8ab34 100644 --- a/src/java/com/sun/gluegen/JavaEmitter.java +++ b/src/java/com/sun/gluegen/JavaEmitter.java @@ -39,6 +39,8 @@ package com.sun.gluegen; +import com.jogamp.common.nio.Buffers; +import com.jogamp.common.os.DynamicLookupHelper; import java.io.*; import java.util.*; import java.text.MessageFormat; @@ -869,6 +871,8 @@ public class JavaEmitter implements GlueEmitter { writer.println("import java.nio.*;"); writer.println(); writer.println("import " + cfg.gluegenRuntimePackage() + ".*;"); + writer.println("import " + DynamicLookupHelper.class.getPackage().getName() + ".*;"); + writer.println("import " + Buffers.class.getPackage().getName() + ".*;"); writer.println(); List imports = cfg.imports(); for (String str : imports) { diff --git a/src/java/com/sun/gluegen/JavaType.java b/src/java/com/sun/gluegen/JavaType.java index 23f48b2..c3cce38 100644 --- a/src/java/com/sun/gluegen/JavaType.java +++ b/src/java/com/sun/gluegen/JavaType.java @@ -197,13 +197,13 @@ public class JavaType { public static JavaType forNIOInt64BufferClass() { if(nioInt64BufferType == null) - nioInt64BufferType = createForClass(com.jogamp.gluegen.runtime.Int64Buffer.class); + nioInt64BufferType = createForClass(com.jogamp.common.nio.Int64Buffer.class); return nioInt64BufferType; } public static JavaType forNIOPointerBufferClass() { if(nioPointerBufferType == null) - nioPointerBufferType = createForClass(com.jogamp.gluegen.runtime.PointerBuffer.class); + nioPointerBufferType = createForClass(com.jogamp.common.nio.PointerBuffer.class); return nioPointerBufferType; } @@ -340,8 +340,8 @@ public class JavaType { public boolean isNIOBuffer() { return clazz != null && ( (java.nio.Buffer.class).isAssignableFrom(clazz) || - (com.jogamp.gluegen.runtime.PointerBuffer.class).isAssignableFrom(clazz) || - (com.jogamp.gluegen.runtime.Int64Buffer.class).isAssignableFrom(clazz) ) ; + (com.jogamp.common.nio.PointerBuffer.class).isAssignableFrom(clazz) || + (com.jogamp.common.nio.Int64Buffer.class).isAssignableFrom(clazz) ) ; } public boolean isNIOByteBuffer() { @@ -362,11 +362,11 @@ public class JavaType { } public boolean isNIOInt64Buffer() { - return (clazz == com.jogamp.gluegen.runtime.Int64Buffer.class); + return (clazz == com.jogamp.common.nio.Int64Buffer.class); } public boolean isNIOPointerBuffer() { - return (clazz == com.jogamp.gluegen.runtime.PointerBuffer.class); + return (clazz == com.jogamp.common.nio.PointerBuffer.class); } public boolean isString() { diff --git a/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java b/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java index 96e4e87..e64de92 100644 --- a/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java +++ b/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java @@ -1,8 +1,8 @@ package com.sun.gluegen.test; -import com.jogamp.gluegen.runtime.*; -import java.nio.*; +import com.jogamp.common.os.Platform; +import com.jogamp.common.nio.PointerBuffer; public class TestPointerBufferEndian { public static void main (String[] args) { diff --git a/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java b/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java index 7202056..4fe4008 100644 --- a/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java +++ b/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java @@ -1,7 +1,9 @@ package com.sun.gluegen.test; -import com.jogamp.gluegen.runtime.*; +import com.jogamp.common.os.Platform; +import com.jogamp.common.nio.Buffers; +import com.jogamp.common.nio.StructAccessor; import java.nio.*; public class TestStructAccessorEndian { diff --git a/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java b/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java index f144a26..b4f8536 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java +++ b/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java @@ -32,10 +32,10 @@ package com.jogamp.gluegen.test.junit; -import com.jogamp.gluegen.runtime.Buffers; -import com.jogamp.gluegen.runtime.PointerBuffer; -import com.jogamp.gluegen.runtime.Int64Buffer; -import com.jogamp.gluegen.runtime.Platform; +import com.jogamp.common.nio.Buffers; +import com.jogamp.common.nio.PointerBuffer; +import com.jogamp.common.nio.Int64Buffer; +import com.jogamp.common.os.Platform; import java.nio.*; import java.io.File; import java.lang.reflect.InvocationTargetException; diff --git a/src/junit/com/jogamp/gluegen/test/junit/Test1p1JavaEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/Test1p1JavaEmitter.java index 54d82f9..c5ef4ad 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/Test1p1JavaEmitter.java +++ b/src/junit/com/jogamp/gluegen/test/junit/Test1p1JavaEmitter.java @@ -34,8 +34,8 @@ package com.jogamp.gluegen.test.junit; import com.jogamp.gluegen.test.junit.impl.BindingTest1p1Impl; -import com.jogamp.gluegen.runtime.Buffers; -import com.jogamp.gluegen.runtime.PointerBuffer; +import com.jogamp.common.nio.Buffers; +import com.jogamp.common.nio.PointerBuffer; import java.nio.*; import java.io.File; import java.lang.reflect.InvocationTargetException; diff --git a/src/junit/com/jogamp/gluegen/test/junit/Test1p2ProcAddressEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/Test1p2ProcAddressEmitter.java index 3bf90e9..9096eca 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/Test1p2ProcAddressEmitter.java +++ b/src/junit/com/jogamp/gluegen/test/junit/Test1p2ProcAddressEmitter.java @@ -34,10 +34,10 @@ package com.jogamp.gluegen.test.junit; import com.jogamp.gluegen.test.junit.impl.BindingTest1p2Impl; -import com.jogamp.gluegen.runtime.Buffers; -import com.jogamp.gluegen.runtime.PointerBuffer; -import com.jogamp.gluegen.runtime.NativeLibrary; -import com.jogamp.gluegen.runtime.DynamicLookupHelper; +import com.jogamp.common.nio.Buffers; +import com.jogamp.common.nio.PointerBuffer; +import com.jogamp.common.os.NativeLibrary; +import com.jogamp.common.os.DynamicLookupHelper; import java.nio.*; import java.io.File; import java.lang.reflect.InvocationTargetException; diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1-common.cfg b/src/junit/com/jogamp/gluegen/test/junit/test1-common.cfg index 2709e80..6ba4b78 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/test1-common.cfg +++ b/src/junit/com/jogamp/gluegen/test/junit/test1-common.cfg @@ -28,6 +28,9 @@ CustomCCode #include "test1.h" # Imports needed by all glue code Import java.nio.* Import java.util.* +Import com.jogamp.common.util.* +Import com.jogamp.common.os.* +Import com.jogamp.common.nio.* diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1p2-gluegen.cfg b/src/junit/com/jogamp/gluegen/test/junit/test1p2-gluegen.cfg index 1ec1b6d..651c93c 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/test1p2-gluegen.cfg +++ b/src/junit/com/jogamp/gluegen/test/junit/test1p2-gluegen.cfg @@ -26,7 +26,6 @@ Include ../../../../../../../make/config/intptr.cfg Import com.jogamp.gluegen.test.junit.BindingTest1 Import com.jogamp.gluegen.test.junit.BindingTest1p2 -Import com.jogamp.gluegen.runtime.* CustomJavaCode BindingTest1p2Impl private static BindingTest1p2ProcAddressTable _table = new BindingTest1p2ProcAddressTable(); CustomJavaCode BindingTest1p2Impl public static void resetProcAddressTable(DynamicLookupHelper lookup) { diff --git a/src/native/common/Platform.c b/src/native/common/Platform.c index 0cc7adc..f0e4e11 100644 --- a/src/native/common/Platform.c +++ b/src/native/common/Platform.c @@ -4,7 +4,7 @@ #include JNIEXPORT jint JNICALL -Java_com_jogamp_gluegen_runtime_Platform_getPointerSizeInBitsImpl(JNIEnv *env, jclass _unused) { +Java_com_jogamp_common_os_Platform_getPointerSizeInBitsImpl(JNIEnv *env, jclass _unused) { return sizeof(void *) * 8; } diff --git a/src/native/common/PointerBuffer.c b/src/native/common/PointerBuffer.c index 9736edc..05e003b 100644 --- a/src/native/common/PointerBuffer.c +++ b/src/native/common/PointerBuffer.c @@ -4,7 +4,7 @@ #include JNIEXPORT jlong JNICALL -Java_com_jogamp_gluegen_runtime_PointerBuffer_getDirectBufferAddressImpl(JNIEnv *env, jclass _unused, jobject directBuffer) { +Java_com_jogamp_common_nio_PointerBuffer_getDirectBufferAddressImpl(JNIEnv *env, jclass _unused, jobject directBuffer) { return ( NULL != directBuffer ) ? ( jlong) (*env)->GetDirectBufferAddress(env, directBuffer) : 0L ; } diff --git a/src/native/macosx/MacOSXDynamicLinkerImpl_JNI.c b/src/native/macosx/MacOSXDynamicLinkerImpl_JNI.c index e6017d7..02f2b5c 100755 --- a/src/native/macosx/MacOSXDynamicLinkerImpl_JNI.c +++ b/src/native/macosx/MacOSXDynamicLinkerImpl_JNI.c @@ -8,12 +8,12 @@ #include /* Java->C glue code: - * Java package: com.jogamp.gluegen.runtime.MacOSXDynamicLinkerImpl + * Java package: com.jogamp.common.os.MacOSXDynamicLinkerImpl * Java method: int dlclose(long __handle) * C function: int dlclose(void * __handle); */ JNIEXPORT jint JNICALL -Java_com_jogamp_gluegen_runtime_MacOSXDynamicLinkerImpl_dlclose__J(JNIEnv *env, jclass _unused, jlong __handle) { +Java_com_jogamp_common_os_MacOSXDynamicLinkerImpl_dlclose__J(JNIEnv *env, jclass _unused, jlong __handle) { int _res; _res = dlclose((void *) (intptr_t) __handle); return _res; @@ -21,12 +21,12 @@ Java_com_jogamp_gluegen_runtime_MacOSXDynamicLinkerImpl_dlclose__J(JNIEnv *env, /* Java->C glue code: - * Java package: com.jogamp.gluegen.runtime.MacOSXDynamicLinkerImpl + * Java package: com.jogamp.common.os.MacOSXDynamicLinkerImpl * Java method: java.lang.String dlerror() * C function: char * dlerror(void); */ JNIEXPORT jstring JNICALL -Java_com_jogamp_gluegen_runtime_MacOSXDynamicLinkerImpl_dlerror__(JNIEnv *env, jclass _unused) { +Java_com_jogamp_common_os_MacOSXDynamicLinkerImpl_dlerror__(JNIEnv *env, jclass _unused) { char * _res; _res = dlerror(); if (_res == NULL) return NULL; return (*env)->NewStringUTF(env, _res); @@ -34,12 +34,12 @@ Java_com_jogamp_gluegen_runtime_MacOSXDynamicLinkerImpl_dlerror__(JNIEnv *env, j /* Java->C glue code: - * Java package: com.jogamp.gluegen.runtime.MacOSXDynamicLinkerImpl + * Java package: com.jogamp.common.os.MacOSXDynamicLinkerImpl * Java method: long dlopen(java.lang.String __path, int __mode) * C function: void * dlopen(const char * __path, int __mode); */ JNIEXPORT jlong JNICALL -Java_com_jogamp_gluegen_runtime_MacOSXDynamicLinkerImpl_dlopen__Ljava_lang_String_2I(JNIEnv *env, jclass _unused, jstring __path, jint __mode) { +Java_com_jogamp_common_os_MacOSXDynamicLinkerImpl_dlopen__Ljava_lang_String_2I(JNIEnv *env, jclass _unused, jstring __path, jint __mode) { const char* _UTF8__path = NULL; void * _res; if (__path != NULL) { @@ -61,12 +61,12 @@ Java_com_jogamp_gluegen_runtime_MacOSXDynamicLinkerImpl_dlopen__Ljava_lang_Strin /* Java->C glue code: - * Java package: com.jogamp.gluegen.runtime.MacOSXDynamicLinkerImpl + * Java package: com.jogamp.common.os.MacOSXDynamicLinkerImpl * Java method: long dlsym(long __handle, java.lang.String __symbol) * C function: void * dlsym(void * __handle, const char * __symbol); */ JNIEXPORT jlong JNICALL -Java_com_jogamp_gluegen_runtime_MacOSXDynamicLinkerImpl_dlsym__JLjava_lang_String_2(JNIEnv *env, jclass _unused, jlong __handle, jstring __symbol) { +Java_com_jogamp_common_os_MacOSXDynamicLinkerImpl_dlsym__JLjava_lang_String_2(JNIEnv *env, jclass _unused, jlong __handle, jstring __symbol) { const char* _UTF8__symbol = NULL; void * _res; if (__symbol != NULL) { diff --git a/src/native/unix/UnixDynamicLinkerImpl_JNI.c b/src/native/unix/UnixDynamicLinkerImpl_JNI.c index 937c71c..2ea863e 100755 --- a/src/native/unix/UnixDynamicLinkerImpl_JNI.c +++ b/src/native/unix/UnixDynamicLinkerImpl_JNI.c @@ -8,12 +8,12 @@ #include /* Java->C glue code: - * Java package: com.jogamp.gluegen.runtime.UnixDynamicLinkerImpl + * Java package: com.jogamp.common.os.UnixDynamicLinkerImpl * Java method: int dlclose(long arg0) * C function: int dlclose(void * ); */ JNIEXPORT jint JNICALL -Java_com_jogamp_gluegen_runtime_UnixDynamicLinkerImpl_dlclose__J(JNIEnv *env, jclass _unused, jlong arg0) { +Java_com_jogamp_common_os_UnixDynamicLinkerImpl_dlclose__J(JNIEnv *env, jclass _unused, jlong arg0) { int _res; _res = dlclose((void *) (intptr_t) arg0); return _res; @@ -21,12 +21,12 @@ Java_com_jogamp_gluegen_runtime_UnixDynamicLinkerImpl_dlclose__J(JNIEnv *env, jc /* Java->C glue code: - * Java package: com.jogamp.gluegen.runtime.UnixDynamicLinkerImpl + * Java package: com.jogamp.common.os.UnixDynamicLinkerImpl * Java method: java.lang.String dlerror() * C function: char * dlerror(void); */ JNIEXPORT jstring JNICALL -Java_com_jogamp_gluegen_runtime_UnixDynamicLinkerImpl_dlerror__(JNIEnv *env, jclass _unused) { +Java_com_jogamp_common_os_UnixDynamicLinkerImpl_dlerror__(JNIEnv *env, jclass _unused) { char * _res; _res = dlerror(); if (_res == NULL) return NULL; return (*env)->NewStringUTF(env, _res); @@ -34,12 +34,12 @@ Java_com_jogamp_gluegen_runtime_UnixDynamicLinkerImpl_dlerror__(JNIEnv *env, jcl /* Java->C glue code: - * Java package: com.jogamp.gluegen.runtime.UnixDynamicLinkerImpl + * Java package: com.jogamp.common.os.UnixDynamicLinkerImpl * Java method: long dlopen(java.lang.String arg0, int arg1) * C function: void * dlopen(const char * , int); */ JNIEXPORT jlong JNICALL -Java_com_jogamp_gluegen_runtime_UnixDynamicLinkerImpl_dlopen__Ljava_lang_String_2I(JNIEnv *env, jclass _unused, jstring arg0, jint arg1) { +Java_com_jogamp_common_os_UnixDynamicLinkerImpl_dlopen__Ljava_lang_String_2I(JNIEnv *env, jclass _unused, jstring arg0, jint arg1) { const char* _UTF8arg0 = NULL; void * _res; if (arg0 != NULL) { @@ -61,12 +61,12 @@ Java_com_jogamp_gluegen_runtime_UnixDynamicLinkerImpl_dlopen__Ljava_lang_String_ /* Java->C glue code: - * Java package: com.jogamp.gluegen.runtime.UnixDynamicLinkerImpl + * Java package: com.jogamp.common.os.UnixDynamicLinkerImpl * Java method: long dlsym(long arg0, java.lang.String arg1) * C function: void * dlsym(void * , const char * ); */ JNIEXPORT jlong JNICALL -Java_com_jogamp_gluegen_runtime_UnixDynamicLinkerImpl_dlsym__JLjava_lang_String_2(JNIEnv *env, jclass _unused, jlong arg0, jstring arg1) { +Java_com_jogamp_common_os_UnixDynamicLinkerImpl_dlsym__JLjava_lang_String_2(JNIEnv *env, jclass _unused, jlong arg0, jstring arg1) { const char* _UTF8arg1 = NULL; void * _res; if (arg1 != NULL) { diff --git a/src/native/windows/WindowsDynamicLinkerImpl_JNI.c b/src/native/windows/WindowsDynamicLinkerImpl_JNI.c index 35ea742..5d30a30 100755 --- a/src/native/windows/WindowsDynamicLinkerImpl_JNI.c +++ b/src/native/windows/WindowsDynamicLinkerImpl_JNI.c @@ -17,12 +17,12 @@ #endif /* Java->C glue code: - * Java package: com.jogamp.gluegen.runtime.WindowsDynamicLinkerImpl + * Java package: com.jogamp.common.os.WindowsDynamicLinkerImpl * Java method: int FreeLibrary(long hLibModule) * C function: BOOL FreeLibrary(HANDLE hLibModule); */ JNIEXPORT jint JNICALL -Java_com_jogamp_gluegen_runtime_WindowsDynamicLinkerImpl_FreeLibrary__J(JNIEnv *env, jclass _unused, jlong hLibModule) { +Java_com_jogamp_common_os_WindowsDynamicLinkerImpl_FreeLibrary__J(JNIEnv *env, jclass _unused, jlong hLibModule) { BOOL _res; _res = FreeLibrary((HANDLE) (intptr_t) hLibModule); return _res; @@ -30,12 +30,12 @@ Java_com_jogamp_gluegen_runtime_WindowsDynamicLinkerImpl_FreeLibrary__J(JNIEnv * /* Java->C glue code: - * Java package: com.jogamp.gluegen.runtime.WindowsDynamicLinkerImpl + * Java package: com.jogamp.common.os.WindowsDynamicLinkerImpl * Java method: int GetLastError() * C function: DWORD GetLastError(void); */ JNIEXPORT jint JNICALL -Java_com_jogamp_gluegen_runtime_WindowsDynamicLinkerImpl_GetLastError__(JNIEnv *env, jclass _unused) { +Java_com_jogamp_common_os_WindowsDynamicLinkerImpl_GetLastError__(JNIEnv *env, jclass _unused) { DWORD _res; _res = GetLastError(); return _res; @@ -43,12 +43,12 @@ Java_com_jogamp_gluegen_runtime_WindowsDynamicLinkerImpl_GetLastError__(JNIEnv * /* Java->C glue code: - * Java package: com.jogamp.gluegen.runtime.WindowsDynamicLinkerImpl + * Java package: com.jogamp.common.os.WindowsDynamicLinkerImpl * Java method: long GetProcAddressA(long hModule, java.lang.String lpProcName) * C function: PROC GetProcAddressA(HANDLE hModule, LPCSTR lpProcName); */ JNIEXPORT jlong JNICALL -Java_com_jogamp_gluegen_runtime_WindowsDynamicLinkerImpl_GetProcAddressA__JLjava_lang_String_2(JNIEnv *env, jclass _unused, jlong hModule, jstring lpProcName) { +Java_com_jogamp_common_os_WindowsDynamicLinkerImpl_GetProcAddressA__JLjava_lang_String_2(JNIEnv *env, jclass _unused, jlong hModule, jstring lpProcName) { const char* _strchars_lpProcName = NULL; PROC _res; if (lpProcName != NULL) { @@ -68,12 +68,12 @@ Java_com_jogamp_gluegen_runtime_WindowsDynamicLinkerImpl_GetProcAddressA__JLjava /* Java->C glue code: - * Java package: com.jogamp.gluegen.runtime.WindowsDynamicLinkerImpl + * Java package: com.jogamp.common.os.WindowsDynamicLinkerImpl * Java method: long LoadLibraryW(java.lang.String lpLibFileName) * C function: HANDLE LoadLibraryW(LPCWSTR lpLibFileName); */ JNIEXPORT jlong JNICALL -Java_com_jogamp_gluegen_runtime_WindowsDynamicLinkerImpl_LoadLibraryW__Ljava_lang_String_2(JNIEnv *env, jclass _unused, jstring lpLibFileName) { +Java_com_jogamp_common_os_WindowsDynamicLinkerImpl_LoadLibraryW__Ljava_lang_String_2(JNIEnv *env, jclass _unused, jstring lpLibFileName) { jchar* _strchars_lpLibFileName = NULL; HANDLE _res; if (lpLibFileName != NULL) { -- cgit v1.2.3