aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/nio/NativeBuffer.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-06-16 00:43:11 +0200
committerSven Gothel <[email protected]>2023-06-16 00:43:11 +0200
commit03c548d96e5c81d0fc39503fe3042cf03e0a75e2 (patch)
tree604aa5b285e5f0476727f0d9b3d23aaf557833a3 /src/java/com/jogamp/common/nio/NativeBuffer.java
parentffd0c48999daa2b321a00fb9ad7ba175734486e3 (diff)
GlueGen Struct [1]: Enhance com.jogamp.common.nio.* to serve a most native-free-code Struct-Code generation
Recfactored all NIO buffer utils to Buffers, i.e. buffer <-> address, memcpy, strnlen, etc Buffers: - Added copyNativeToDirectByteBuffer(..), allowing to copy a native memory slice into a direct buffer. - Added typeNameToBufferClass(String) and sizeOfBufferElem(Class<? extends Buffer>) - Completed slize2<Type>(..) buffer-mapping methods - Exposure of safe getDirectByteBuffer(..) w/ null-check (package private) Added NativeBuffer.storeDirectAddress(..), allowing to write the array address into a native buffer (struct, etc), allowing to referencing the ElementBuffer (linear array of elements) and PointerBuffer (array of pointer). Hint: This can be read via PointerBuffer.wrap(..).get(0) Added ElementBuffer (a NativeBuffer) mapping an array of elements, completing native abstraction next to PointerBuffer (array of pointer). ElementBuffer can dereference an existing element-array by native address via ElementBuffer.derefPointer(..). Views of its content can be directly accessed via ElementBuffer.slice(..). +++ These utilities and buffer abstractions will allow to reuse code and simplify the GlueGen struct get/set implementations and help to reduce native code injection.
Diffstat (limited to 'src/java/com/jogamp/common/nio/NativeBuffer.java')
-rw-r--r--src/java/com/jogamp/common/nio/NativeBuffer.java36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/java/com/jogamp/common/nio/NativeBuffer.java b/src/java/com/jogamp/common/nio/NativeBuffer.java
index d81da9d..5ee6af8 100644
--- a/src/java/com/jogamp/common/nio/NativeBuffer.java
+++ b/src/java/com/jogamp/common/nio/NativeBuffer.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010 JogAmp Community. All rights reserved.
+ * Copyright 2010-2023 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -32,6 +32,7 @@
package com.jogamp.common.nio;
import java.nio.Buffer;
+import java.nio.ByteBuffer;
/**
* Hardware independent container for various kinds of buffers.
@@ -76,19 +77,34 @@ public interface NativeBuffer<B extends NativeBuffer> {
*/
public Object array() throws UnsupportedOperationException ;
+ /** Returns the underlying buffer object. */
public Buffer getBuffer();
-
+ /** Return true if the underlying buffer is NIO direct, otherwise false. */
public boolean isDirect();
+ /** Returns the native address of the underlying buffer if {@link #isDirect()}, otherwise {@code 0}. */
+ public long getDirectBufferAddress();
+ /**
+ * Store the {@link #getDirectBufferAddress()} into the given {@link ByteBuffer} using relative put.
+ * <p>
+ * The native pointer value is stored either as a 32bit (int) or 64bit (long) wide value,
+ * depending of the CPU pointer width.
+ * </p>
+ */
+ public void storeDirectAddress(final ByteBuffer directDest);
+ /**
+ * Store the {@link #getDirectBufferAddress()} into the given {@link ByteBuffer} using absolute put.
+ * <p>
+ * The native pointer value is stored either as a 32bit (int) or 64bit (long) wide value,
+ * depending of the CPU pointer width.
+ * </p>
+ **/
+ public void storeDirectAddress(final ByteBuffer directDest, final int destOffset);
public B rewind();
- public B put(int index, long value);
-
- public B put(long value);
-
+ /**
+ * Relative bulk get method. Copy the source values <code> src[position .. capacity] [</code>
+ * to this buffer and increment the position by <code>capacity-position</code>.
+ */
public B put(B src);
-
- public long get();
-
- public long get(int idx);
}