aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/nio/Buffers.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-04-27 19:47:43 +0200
committerSven Gothel <[email protected]>2011-04-27 19:47:43 +0200
commit8f8aa3f73e3c9804c4a86f5d4fdac257d50d831a (patch)
tree87497a9ffd60f4d3c2be2535312a72f84087a23d /src/java/com/jogamp/common/nio/Buffers.java
parenta07892f07f15c96ca248fc12133748be7058241f (diff)
NativeBuffer/PointerBuffer API/Impl Change (remove explicit backup array, alloc referenced data map if used only)
This patch doesn't impact GlueGen's code generation, but enhance and fix PointerBuffer usage only. remove explicit backup array As suggested by Michael Bien with a proposed patch, PointerBuffer's backup array is not only redundant in case it's not used, but also erroneous - due to possible sliced buffers. Removes the explicit backup array implementation leaving it up to the user, ie how PointerBuffer is created (alloc/allocDirect) and use the underlying nio's buffer backup array, if available. This also fixes the (never tested) case of indirect w/ backup array usage on 32bit platform size. In this case the array shall be of type int[], holding 32bit pointer - on 64bit long[]. Previous to this patch, it was always long[]. Added more thorough tests of PointerBuffer, notably indirect w/ backup array and native deep copy and filling of a pointer array. alloc referenced data map if used only As suggested by Michael Bien with a proposed patch, the allocation of the dataMap hash map is redundant in case it's not used. The hash map will be initialized lazy, if needed only.
Diffstat (limited to 'src/java/com/jogamp/common/nio/Buffers.java')
-rwxr-xr-xsrc/java/com/jogamp/common/nio/Buffers.java26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/java/com/jogamp/common/nio/Buffers.java b/src/java/com/jogamp/common/nio/Buffers.java
index ed9323e..0d30026 100755
--- a/src/java/com/jogamp/common/nio/Buffers.java
+++ b/src/java/com/jogamp/common/nio/Buffers.java
@@ -329,9 +329,9 @@ public class Buffers {
} else if (buf instanceof CharBuffer) {
return pos * SIZEOF_CHAR;
}
- } else if (buf instanceof PointerBuffer) {
- PointerBuffer pointerBuffer = (PointerBuffer) buf;
- return pointerBuffer.position() * PointerBuffer.elementSize();
+ } else if (buf instanceof NativeBuffer) {
+ final NativeBuffer nb = (NativeBuffer) buf;
+ return nb.position() * nb.elementSize() ;
}
throw new IllegalArgumentException("Disallowed array backing store type in buffer " + buf.getClass().getName());
@@ -340,15 +340,17 @@ public class Buffers {
/**
* Helper routine to return the array backing store reference from
* a Buffer object.
+ * @throws UnsupportedOperationException if the passed Object does not have an array backing store
+ * @throws IllegalArgumentException if the passed Object is neither of type {@link java.nio.Buffer} or {@link NativeBuffer}.
*/
- public static Object getArray(Object buf) {
+ public static Object getArray(Object buf) throws UnsupportedOperationException, IllegalArgumentException {
if (buf == null) {
return null;
}
if (buf instanceof Buffer) {
return ((Buffer) buf).array();
- } else if (buf instanceof PointerBuffer) {
- return ((PointerBuffer) buf).array();
+ } else if (buf instanceof NativeBuffer) {
+ return ((NativeBuffer) buf).array();
}
throw new IllegalArgumentException("Disallowed array backing store type in buffer " + buf.getClass().getName());
@@ -381,9 +383,9 @@ public class Buffers {
} else if (buf instanceof CharBuffer) {
return (SIZEOF_CHAR * (((CharBuffer) buf).arrayOffset() + pos));
}
- } else if (buf instanceof PointerBuffer) {
- PointerBuffer pointerBuffer = (PointerBuffer) buf;
- return PointerBuffer.elementSize() * (pointerBuffer.arrayOffset() + pointerBuffer.position());
+ } else if (buf instanceof NativeBuffer) {
+ final NativeBuffer nb = (NativeBuffer) buf;
+ return nb.elementSize() * ( nb.arrayOffset() + nb.position() );
}
throw new IllegalArgumentException("Unknown buffer type " + buf.getClass().getName());
@@ -772,9 +774,9 @@ public class Buffers {
} else if (buffer instanceof CharBuffer) {
bytesRemaining = elementsRemaining * SIZEOF_CHAR;
}
- } else if (buffer instanceof PointerBuffer) {
- PointerBuffer pointerBuffer = (PointerBuffer) buffer;
- bytesRemaining = pointerBuffer.remaining() * PointerBuffer.elementSize();
+ } else if (buffer instanceof NativeBuffer) {
+ final NativeBuffer nb = (NativeBuffer) buffer;
+ bytesRemaining = nb.remaining() * nb.elementSize();
}
if (bytesRemaining < minBytesRemaining) {
throw new IndexOutOfBoundsException("Required " + minBytesRemaining + " remaining bytes in buffer, only had " + bytesRemaining);