From 03c548d96e5c81d0fc39503fe3042cf03e0a75e2 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 16 Jun 2023 00:43:11 +0200 Subject: 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) - Completed slize2(..) 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. --- src/java/com/jogamp/common/nio/StructAccessor.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/java/com/jogamp/common/nio/StructAccessor.java') diff --git a/src/java/com/jogamp/common/nio/StructAccessor.java b/src/java/com/jogamp/common/nio/StructAccessor.java index 8ae0c29..79e8a36 100644 --- a/src/java/com/jogamp/common/nio/StructAccessor.java +++ b/src/java/com/jogamp/common/nio/StructAccessor.java @@ -1,6 +1,6 @@ /* + * Copyright (c) 2010-2023 JogAmp Community. All rights reserved. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2010 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 @@ -42,22 +42,28 @@ package com.jogamp.common.nio; import java.nio.*; /** - * @author Kenneth Russel, et al. + * @author Kenneth Russel, Sven Gothel, Michael Bien, et al. */ public class StructAccessor { private final ByteBuffer bb; + /** Create a new instance. The {@link ByteBuffer} will be {@link ByteBuffer#rewind()} and native-order to be used with native code set. */ public StructAccessor(final ByteBuffer bb) { - // Setting of byte order is concession to native code which needs - // to instantiate these this.bb = bb.order(ByteOrder.nativeOrder()); + this.bb.rewind(); } + /** Return the underlying native direct ByteBuffer */ public final ByteBuffer getBuffer() { return bb; } + /** Returns the native address of the underlying native ByteBuffer. */ + public final long getDirectBufferAddress() { + return Buffers.getDirectBufferAddressImpl(bb); + } + /** * Returns a slice of the current ByteBuffer starting at the * specified byte offset and extending the specified number of -- cgit v1.2.3