From c28d5c8d0d83670a548671a1d0da55e3447ea0c7 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Tue, 25 Jun 2013 09:31:04 +0200
Subject: Refine commit 5e01e993aeba4e95fc8aa6e75b3e295011e27bbb, skip
 Buffers.sizeOfBufferElem(..) call.

---
 src/java/com/jogamp/common/nio/AbstractBuffer.java | 25 +++++++++++++---------
 1 file changed, 15 insertions(+), 10 deletions(-)

(limited to 'src/java/com/jogamp/common/nio/AbstractBuffer.java')

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;
-- 
cgit v1.2.3