aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/java/com/jogamp/gluegen/runtime/PointerBuffer.java52
-rw-r--r--src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java46
-rw-r--r--src/native/common/Platform.c (renamed from src/native/common/CPU.c)0
-rw-r--r--src/native/common/PointerBuffer.c10
4 files changed, 106 insertions, 2 deletions
diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java
index 0adbb36..3ee7b54 100644
--- a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java
+++ b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java
@@ -31,6 +31,8 @@
package com.jogamp.gluegen.runtime;
import java.nio.ByteBuffer;
+import java.nio.Buffer;
+import java.util.HashMap;
/**
* Hardware independent container for native pointer arrays.
@@ -48,6 +50,12 @@ public abstract class PointerBuffer {
protected int position;
protected long[] backup;
+ protected HashMap/*<aptr, buffer>*/ dataMap = new HashMap();
+
+ static {
+ NativeLibrary.ensureNativeLibLoaded();
+ }
+
protected PointerBuffer(ByteBuffer bb) {
this.bb = bb;
}
@@ -152,10 +160,54 @@ public abstract class PointerBuffer {
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();
diff --git a/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java b/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java
index 420dc2b..f144a26 100644
--- a/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java
+++ b/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java
@@ -212,6 +212,7 @@ public class BaseTest1 {
result = binding.arrayTestFooNioOnly(context, lb1);
Assert.assertTrue("Wrong result: "+result, 1+8000==result);
+ // Int64Buffer arrayTestFoo2 ( Int64Buffer )
{
lb2.rewind();
Int64Buffer lb3 = Int64Buffer.allocateDirect(BindingTest1.ARRAY_SIZE);
@@ -236,6 +237,8 @@ public class BaseTest1 {
Assert.assertTrue("Wrong result: s:"+lb3.get(j)+" d: "+lbR.get(j), 1+lb3.get(j)==lbR.get(j));
}
}
+
+ // Int64Buffer arrayTestFoo2 ( long[], int )
{
long[] larray3 = new long[BindingTest1.ARRAY_SIZE];
for(i=0; i<BindingTest1.ARRAY_SIZE; i++) {
@@ -252,10 +255,13 @@ public class BaseTest1 {
Assert.assertTrue("Wrong result: s:"+larray3[j]+" d: "+lbR.get(j), 1+larray3[j]==lbR.get(j));
}
}
+
+ // PointerBuffer arrayTestFoo3ArrayToPtrPtr(Int64Buffer)
+ // PointerBuffer arrayTestFoo3PtrPtr(PointerBuffer)
{
lb2.rewind();
Int64Buffer lb3 = Int64Buffer.allocateDirect(BindingTest1.ARRAY_SIZE*BindingTest1.ARRAY_SIZE);
- int j=0;
+ int j;
for(j=0; j<BindingTest1.ARRAY_SIZE; j++) {
lb3.put(lb2);
lb2.rewind();
@@ -276,8 +282,44 @@ public class BaseTest1 {
Assert.assertNotNull(pb2);
Assert.assertTrue("Wrong result: "+pb2.capacity(), BindingTest1.ARRAY_SIZE == pb2.capacity());
Assert.assertTrue("Wrong result: "+pb2.remaining(), BindingTest1.ARRAY_SIZE == pb2.remaining());
+ for(j=0; j<BindingTest1.ARRAY_SIZE*BindingTest1.ARRAY_SIZE; j++) {
+ Assert.assertTrue("Wrong result: s:"+lb2.get(j%BindingTest1.ARRAY_SIZE)+" d: "+lb3.get(j),
+ 1+lb2.get(j%BindingTest1.ARRAY_SIZE)==lb3.get(j));
+ }
+ }
+
+ // PointerBuffer.referenceBuffer(Int64Buffer.getBuffer)
+ // " "
+ // PointerBuffer arrayTestFoo3PtrPtr(PointerBuffer)
+ {
+ PointerBuffer pb = PointerBuffer.allocateDirect(BindingTest1.ARRAY_SIZE);
+ int j;
+ for(j=0; j<BindingTest1.ARRAY_SIZE; j++) {
+ Int64Buffer lb3 = Int64Buffer.allocateDirect(BindingTest1.ARRAY_SIZE);
+ lb3.put(lb2);
+ lb2.rewind();
+ lb3.rewind();
+
+ pb.referenceBuffer(lb3.getBuffer());
+ }
+ pb.rewind();
+
+ // System.out.println("lb3: "+lb3);
+ Assert.assertTrue("Wrong result: "+pb.capacity(), BindingTest1.ARRAY_SIZE == pb.capacity());
+ Assert.assertTrue("Wrong result: "+pb.remaining(), BindingTest1.ARRAY_SIZE == pb.remaining());
+ Assert.assertTrue("Wrong result: "+pb.getReferencedBuffer(0)+" != "+lb2.getBuffer(), pb.getReferencedBuffer(0).equals(lb2.getBuffer()));
+
+ PointerBuffer pb2 = binding.arrayTestFoo3PtrPtr(pb);
+
+ Assert.assertNotNull(pb2);
+ Assert.assertTrue("Wrong result: "+pb2.capacity(), BindingTest1.ARRAY_SIZE == pb2.capacity());
+ Assert.assertTrue("Wrong result: "+pb2.remaining(), BindingTest1.ARRAY_SIZE == pb2.remaining());
for(j=0; j<BindingTest1.ARRAY_SIZE; j++) {
- Assert.assertTrue("Wrong result: s:"+lb2.get(j)+" d: "+lb3.get(j), 1+lb2.get(j)==lb3.get(j));
+ ByteBuffer bb = (ByteBuffer) pb.getReferencedBuffer(j);
+ Int64Buffer i64b = Int64Buffer.wrap(bb);
+ for(i=0; i<BindingTest1.ARRAY_SIZE; i++) {
+ Assert.assertTrue("Wrong result: ["+j+"]["+i+"] s:"+lb2.get(i)+" d: "+i64b.get(i), 1+lb2.get(i)==i64b.get(i));
+ }
}
}
diff --git a/src/native/common/CPU.c b/src/native/common/Platform.c
index 0cc7adc..0cc7adc 100644
--- a/src/native/common/CPU.c
+++ b/src/native/common/Platform.c
diff --git a/src/native/common/PointerBuffer.c b/src/native/common/PointerBuffer.c
new file mode 100644
index 0000000..9736edc
--- /dev/null
+++ b/src/native/common/PointerBuffer.c
@@ -0,0 +1,10 @@
+
+#include <jni.h>
+
+#include <assert.h>
+
+JNIEXPORT jlong JNICALL
+Java_com_jogamp_gluegen_runtime_PointerBuffer_getDirectBufferAddressImpl(JNIEnv *env, jclass _unused, jobject directBuffer) {
+ return ( NULL != directBuffer ) ? ( jlong) (*env)->GetDirectBufferAddress(env, directBuffer) : 0L ;
+}
+