aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-06-25 09:31:04 +0200
committerSven Gothel <[email protected]>2013-06-25 09:31:04 +0200
commitc28d5c8d0d83670a548671a1d0da55e3447ea0c7 (patch)
treed13acf6876a404389821c2a7beb900c5962889d3 /src/java/com
parent72f60a534db7c0b731d4dca83481679817ad7574 (diff)
Refine commit 5e01e993aeba4e95fc8aa6e75b3e295011e27bbb, skip Buffers.sizeOfBufferElem(..) call.
Diffstat (limited to 'src/java/com')
-rw-r--r--src/java/com/jogamp/common/nio/AbstractBuffer.java25
-rw-r--r--src/java/com/jogamp/common/nio/PointerBuffer.java15
2 files changed, 22 insertions, 18 deletions
diff --git a/src/java/com/jogamp/common/nio/AbstractBuffer.java b/src/java/com/jogamp/common/nio/AbstractBuffer.java
index 2624254..4afff2a 100644
--- a/src/java/com/jogamp/common/nio/AbstractBuffer.java
+++ b/src/java/com/jogamp/common/nio/AbstractBuffer.java
@@ -42,9 +42,9 @@ import java.nio.Buffer;
@SuppressWarnings("rawtypes")
public abstract class AbstractBuffer<B extends AbstractBuffer> implements NativeBuffer<B> {
- protected final int elementSize;
protected final Buffer buffer;
- protected int capacity;
+ protected final int elementSize;
+ protected final int capacity;
protected int position;
static {
@@ -52,15 +52,20 @@ public abstract class AbstractBuffer<B extends AbstractBuffer> implements Native
}
/**
- * @param buffer expected in target format
- * @param elementSize the target element size in bytes
+ * capacity and elementSize should be match the equation w/ target buffer type
+ * <pre>
+ * capacity = elementSizeInBytes(buffer) * buffer.capacity() ) / elementSize
+ * </pre>
+ * @param buffer shall be in target format.
+ * @param elementSize the target element size in bytes.
+ * @param capacity the target capacity in elements of size <code>elementSize</code>.
*/
- protected AbstractBuffer(Buffer buffer, int elementSize) {
- this.elementSize = elementSize;
+ protected AbstractBuffer(Buffer buffer, int elementSize, int capacity) {
this.buffer = buffer;
-
- capacity = ( Buffers.sizeOfBufferElem(buffer) * buffer.capacity() ) / elementSize ;
- position = 0;
+ this.elementSize = elementSize;
+ this.capacity = capacity;
+
+ this.position = 0;
}
public final int elementSize() {
@@ -114,7 +119,7 @@ public abstract class AbstractBuffer<B extends AbstractBuffer> implements Native
}
public final int arrayOffset() {
- if(hasArray()) {
+ if( hasArray() ) {
return buffer.arrayOffset();
} else {
return 0;
diff --git a/src/java/com/jogamp/common/nio/PointerBuffer.java b/src/java/com/jogamp/common/nio/PointerBuffer.java
index f05c6ad..df1c4b1 100644
--- a/src/java/com/jogamp/common/nio/PointerBuffer.java
+++ b/src/java/com/jogamp/common/nio/PointerBuffer.java
@@ -57,18 +57,18 @@ public class PointerBuffer extends AbstractBuffer<PointerBuffer> {
}
/** no backup array, use for direct usage only */
- PointerBuffer(ByteBuffer bb) {
- super(Platform.is32Bit() ? bb.asIntBuffer() : bb.asLongBuffer(), ELEMENT_SIZE);
+ static PointerBuffer create(ByteBuffer bb) {
+ return Platform.is32Bit() ? new PointerBuffer( bb.asIntBuffer() ) : new PointerBuffer( bb.asLongBuffer() );
}
/** supports backup array */
PointerBuffer(IntBuffer b) {
- super(b, ELEMENT_SIZE);
+ super(b, ELEMENT_SIZE, b.capacity());
}
/** supports backup array */
PointerBuffer(LongBuffer b) {
- super(b, ELEMENT_SIZE);
+ super(b, ELEMENT_SIZE, b.capacity());
}
private final void validateDataMap() {
@@ -89,16 +89,16 @@ public class PointerBuffer extends AbstractBuffer<PointerBuffer> {
/** Returns a direct PointerBuffer in native order, w/o backup array */
public static PointerBuffer allocateDirect(int size) {
- return new PointerBuffer(Buffers.newDirectByteBuffer(ELEMENT_SIZE * size));
+ return create(Buffers.newDirectByteBuffer(ELEMENT_SIZE * size));
}
public static PointerBuffer wrap(ByteBuffer src) {
- return new PointerBuffer(src);
+ return create(src);
}
/**
* @return new PointerBuffer sharing the same buffer data of this instance (identity),
- * but having independent position, limit and capacity.
+ * but having an independent position.
*/
public final PointerBuffer duplicate() {
PointerBuffer npb;
@@ -110,7 +110,6 @@ public class PointerBuffer extends AbstractBuffer<PointerBuffer> {
if(null != dataMap) {
npb.dataMap = (LongObjectHashMap) dataMap.clone();
}
- npb.capacity = capacity;
npb.position = position;
return npb;
}