diff options
-rw-r--r-- | make/config/jogl/egl-common.cfg | 2 | ||||
-rw-r--r-- | make/config/jogl/glu-base.cfg | 1 | ||||
-rw-r--r-- | make/config/jogl/glu-gl2.cfg | 1 | ||||
-rw-r--r-- | make/config/jogl/glu-gl2es1.cfg | 1 | ||||
-rw-r--r-- | make/config/jogl/glx-CustomCCode.c | 16 | ||||
-rw-r--r-- | make/config/jogl/glx-CustomJavaCode.java | 16 | ||||
-rw-r--r-- | make/config/jogl/glx-x11.cfg | 2 | ||||
-rw-r--r-- | make/config/jogl/wgl-win32.cfg | 3 | ||||
-rw-r--r-- | make/config/nativewindow/drm-gbm-lib.cfg | 18 | ||||
-rw-r--r-- | make/config/nativewindow/jawt-common.cfg | 10 | ||||
-rw-r--r-- | make/config/nativewindow/win32-lib.cfg | 8 | ||||
-rw-r--r-- | make/config/nativewindow/x11-lib.cfg | 4 | ||||
-rw-r--r-- | make/config/oculusvr/oculusvr.cfg | 1 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java | 163 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureEmitter.java | 15 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureJavaMethodBindingEmitter.java | 234 |
16 files changed, 263 insertions, 232 deletions
diff --git a/make/config/jogl/egl-common.cfg b/make/config/jogl/egl-common.cfg index 6728588c2..fc52de19d 100644 --- a/make/config/jogl/egl-common.cfg +++ b/make/config/jogl/egl-common.cfg @@ -25,6 +25,8 @@ Opaque long EGLSyncKHR Opaque boolean EGLBoolean Opaque long void * +ImmutableAccess EGLClientPixmapHI + # Make eglGetProcAddress return an opaque long Opaque long __EGLFuncPtr diff --git a/make/config/jogl/glu-base.cfg b/make/config/jogl/glu-base.cfg index 542f8afef..bfd399705 100644 --- a/make/config/jogl/glu-base.cfg +++ b/make/config/jogl/glu-base.cfg @@ -18,7 +18,6 @@ Ignore gluScaleImage # Custom Java code for GLU class IncludeAs CustomJavaCode GLU glu-CustomJavaCode-base.java -ManualStaticInitCall GLU # Imports for the Error and Registry classes Import jogamp.opengl.glu.error.Error diff --git a/make/config/jogl/glu-gl2.cfg b/make/config/jogl/glu-gl2.cfg index c38f6a6b4..0182f587c 100644 --- a/make/config/jogl/glu-gl2.cfg +++ b/make/config/jogl/glu-gl2.cfg @@ -33,7 +33,6 @@ CustomCCode #include <GL/glu.h> # Custom Java code for GLU class IncludeAs CustomJavaCode GLUgl2 glu-CustomJavaCode-gl2.java -ManualStaticInitCall GLUgl2 # GLU needs access to the GLUtesselatorImpl class for GLUtesselator, # to the Mipmap class for scaling and mipmap generation, diff --git a/make/config/jogl/glu-gl2es1.cfg b/make/config/jogl/glu-gl2es1.cfg index 98217da1f..d983fe0ed 100644 --- a/make/config/jogl/glu-gl2es1.cfg +++ b/make/config/jogl/glu-gl2es1.cfg @@ -18,7 +18,6 @@ Ignore gluScaleImage # Custom Java code for GLU class IncludeAs CustomJavaCode GLUgl2es1 glu-CustomJavaCode-gl2es1.java -ManualStaticInitCall GLUgl2es1 Import com.jogamp.opengl.GLES1 Import jogamp.opengl.glu.mipmap.Mipmap diff --git a/make/config/jogl/glx-CustomCCode.c b/make/config/jogl/glx-CustomCCode.c index b4b4f5b0a..bc3ffa5da 100644 --- a/make/config/jogl/glx-CustomCCode.c +++ b/make/config/jogl/glx-CustomCCode.c @@ -45,7 +45,7 @@ Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXGetFBConfigAttributes(JNIEnv *env, j * C function: XVisualInfo * glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig config); */ JNIEXPORT jobject JNICALL -Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXGetVisualFromFBConfig(JNIEnv *env, jclass _unused, jlong dpy, jlong config, jlong procAddress) { +Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXGetVisualFromFBConfig(JNIEnv *env, jclass _unused, jclass clazzBuffers, jlong dpy, jlong config, jlong procAddress) { typedef XVisualInfo* (APIENTRY*_local_PFNGLXGETVISUALFROMFBCONFIG)(Display * dpy, GLXFBConfig config); _local_PFNGLXGETVISUALFROMFBCONFIG ptr_glXGetVisualFromFBConfig; XVisualInfo * _res; @@ -55,7 +55,7 @@ Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXGetVisualFromFBConfig(JNIEnv *env, j _res = (* ptr_glXGetVisualFromFBConfig) ((Display *) (intptr_t) dpy, (GLXFBConfig) (intptr_t) config); if (_res == NULL) return NULL; - jbyteCopy = JVMUtil_NewDirectByteBufferCopy(env, _res, sizeof(XVisualInfo)); + jbyteCopy = JVMUtil_NewDirectByteBufferCopy(env, clazzBuffers, _res, sizeof(XVisualInfo)); XFree(_res); return jbyteCopy; @@ -67,7 +67,7 @@ Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXGetVisualFromFBConfig(JNIEnv *env, j * C function: GLXFBConfig * glXChooseFBConfig(Display * dpy, int screen, const int * attribList, int * nitems); */ JNIEXPORT jobject JNICALL -Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXChooseFBConfig(JNIEnv *env, jclass _unused, jlong dpy, jint screen, jobject attribList, jint attribList_byte_offset, jobject nitems, jint nitems_byte_offset, jlong procAddress) { +Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXChooseFBConfig(JNIEnv *env, jclass _unused, jclass clazzBuffers, jlong dpy, jint screen, jobject attribList, jint attribList_byte_offset, jobject nitems, jint nitems_byte_offset, jlong procAddress) { typedef GLXFBConfig * (APIENTRY*_local_PFNGLXCHOOSEFBCONFIGPROC)(Display * dpy, int screen, const int * attribList, int * nitems); _local_PFNGLXCHOOSEFBCONFIGPROC ptr_glXChooseFBConfig; int * _attribList_ptr = NULL; @@ -105,7 +105,7 @@ Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXChooseFBConfig(JNIEnv *env, jclass _ } // fprintf(stderr, "glXChooseFBConfig.X: Count %d\n", count); - jbyteCopy = JVMUtil_NewDirectByteBufferCopy(env, _res, count * sizeof(GLXFBConfig)); + jbyteCopy = JVMUtil_NewDirectByteBufferCopy(env, clazzBuffers, _res, count * sizeof(GLXFBConfig)); XFree(_res); return jbyteCopy; @@ -117,7 +117,7 @@ Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXChooseFBConfig(JNIEnv *env, jclass _ * C function: GLXFBConfig * glXGetFBConfigs(Display * dpy, int screen, int * nelements); */ JNIEXPORT jobject JNICALL -Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXGetFBConfigs(JNIEnv *env, jclass _unused, jlong dpy, jint screen, jobject nelements, jint nelements_byte_offset, jlong procAddress) { +Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXGetFBConfigs(JNIEnv *env, jclass _unused, jclass clazzBuffers, jlong dpy, jint screen, jobject nelements, jint nelements_byte_offset, jlong procAddress) { typedef GLXFBConfig * (APIENTRY*_local_PFNGLXGETFBCONFIGSPROC)(Display * dpy, int screen, int * nelements); _local_PFNGLXGETFBCONFIGSPROC ptr_glXGetFBConfigs; int * _nelements_ptr = NULL; @@ -149,7 +149,7 @@ Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXGetFBConfigs(JNIEnv *env, jclass _un } } - jbyteCopy = JVMUtil_NewDirectByteBufferCopy(env, _res, count * sizeof(GLXFBConfig)); + jbyteCopy = JVMUtil_NewDirectByteBufferCopy(env, clazzBuffers, _res, count * sizeof(GLXFBConfig)); XFree(_res); return jbyteCopy; @@ -162,7 +162,7 @@ Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXGetFBConfigs(JNIEnv *env, jclass _un * C function: XVisualInfo * glXChooseVisual(Display * dpy, int screen, int * attribList); */ JNIEXPORT jobject JNICALL -Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXChooseVisual(JNIEnv *env, jclass _unused, jlong dpy, jint screen, jobject attribList, jint attribList_byte_offset, jlong procAddress) { +Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXChooseVisual(JNIEnv *env, jclass _unused, jclass clazzBuffers, jlong dpy, jint screen, jobject attribList, jint attribList_byte_offset, jlong procAddress) { typedef XVisualInfo * (APIENTRY*_local_PFNGLXCHOOSEVISUALPROC)(Display * dpy, int screen, int * attribList); _local_PFNGLXCHOOSEVISUALPROC ptr_glXChooseVisual; int * _attribList_ptr = NULL; @@ -176,7 +176,7 @@ Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXChooseVisual(JNIEnv *env, jclass _un _res = (* ptr_glXChooseVisual) ((Display *) (intptr_t) dpy, (int) screen, (int *) _attribList_ptr); if (NULL == _res) return NULL; - jbyteCopy = JVMUtil_NewDirectByteBufferCopy(env, _res, sizeof(XVisualInfo)); + jbyteCopy = JVMUtil_NewDirectByteBufferCopy(env, clazzBuffers, _res, sizeof(XVisualInfo)); XFree(_res); return jbyteCopy; diff --git a/make/config/jogl/glx-CustomJavaCode.java b/make/config/jogl/glx-CustomJavaCode.java index 5a3ea392b..2a70b4442 100644 --- a/make/config/jogl/glx-CustomJavaCode.java +++ b/make/config/jogl/glx-CustomJavaCode.java @@ -28,13 +28,13 @@ if (__addr_ == 0) { throw new GLException("Method \"glXGetVisualFromFBConfig\" not available"); } - final java.nio.ByteBuffer _res = dispatch_glXGetVisualFromFBConfig(dpy, config, __addr_); + final java.nio.ByteBuffer _res = dispatch_glXGetVisualFromFBConfig(com.jogamp.common.nio.Buffers.class, dpy, config, __addr_); if (_res == null) return null; return XVisualInfo.create(Buffers.nativeOrder(_res)); } /** Entry point to C language function: - Alias for: <br> <code> XVisualInfo * glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig config); </code> */ - private static native java.nio.ByteBuffer dispatch_glXGetVisualFromFBConfig(long dpy, long config, long procAddr); + private static native java.nio.ByteBuffer dispatch_glXGetVisualFromFBConfig(Class clazzBuffers, long dpy, long config, long procAddr); /** Entry point to C language function: <code> GLXFBConfig * glXChooseFBConfig(Display * dpy, int screen, const int * attribList, int * nitems); </code> <br>Part of CORE FUNC @@ -50,7 +50,7 @@ if (__addr_ == 0) { throw new GLException("Method \"glXChooseFBConfig\" not available"); } - final ByteBuffer _res = dispatch_glXChooseFBConfig(dpy, screen, attribList, Buffers.getDirectBufferByteOffset(attribList), nitems, Buffers.getDirectBufferByteOffset(nitems), __addr_); + final ByteBuffer _res = dispatch_glXChooseFBConfig(com.jogamp.common.nio.Buffers.class, dpy, screen, attribList, Buffers.getDirectBufferByteOffset(attribList), nitems, Buffers.getDirectBufferByteOffset(nitems), __addr_); if (_res == null) return null; return PointerBuffer.wrap(Buffers.nativeOrder(_res)); } @@ -58,7 +58,7 @@ /** Entry point to C language function: <code> GLXFBConfig * glXChooseFBConfig(Display * dpy, int screen, const int * attribList, int * nitems); </code> <br>Part of CORE FUNC @param attribList a direct only {@link java.nio.IntBuffer} @param nitems a direct only {@link java.nio.IntBuffer} */ - private static native ByteBuffer dispatch_glXChooseFBConfig(long dpy, int screen, Object attribList, int attribList_byte_offset, Object nitems, int nitems_byte_offset, long procAddress); + private static native ByteBuffer dispatch_glXChooseFBConfig(Class clazzBuffers, long dpy, int screen, Object attribList, int attribList_byte_offset, Object nitems, int nitems_byte_offset, long procAddress); /** Entry point to C language function: <code> GLXFBConfig * glXGetFBConfigs(Display * dpy, int screen, int * nelements); </code> <br>Part of <code>GLX_VERSION_1_3</code> @param nelements a direct only {@link java.nio.IntBuffer} */ @@ -70,14 +70,14 @@ if (__addr_ == 0) { throw new GLException(String.format("Method \"%s\" not available", "glXGetFBConfigs")); } - final ByteBuffer _res = dispatch_glXGetFBConfigs(dpy, screen, nelements, Buffers.getDirectBufferByteOffset(nelements), __addr_); + final ByteBuffer _res = dispatch_glXGetFBConfigs(com.jogamp.common.nio.Buffers.class, dpy, screen, nelements, Buffers.getDirectBufferByteOffset(nelements), __addr_); if (_res == null) return null; return PointerBuffer.wrap(Buffers.nativeOrder(_res)); } /** Entry point to C language function: <code> GLXFBConfig * glXGetFBConfigs(Display * dpy, int screen, int * nelements); </code> <br>Part of <code>GLX_VERSION_1_3</code> @param nelements a direct only {@link java.nio.IntBuffer} */ - private static native ByteBuffer dispatch_glXGetFBConfigs(long dpy, int screen, Object nelements, int nelements_byte_offset, long procAddress); + private static native ByteBuffer dispatch_glXGetFBConfigs(Class clazzBuffers, long dpy, int screen, Object nelements, int nelements_byte_offset, long procAddress); /** Entry point to C language function: <code> XVisualInfo * glXChooseVisual(Display * dpy, int screen, int * attribList); </code> <br>Part of <code>GLX_VERSION_1_X</code> @@ -90,12 +90,12 @@ if (__addr_ == 0) { throw new GLException("Method \"glXChooseVisual\" not available"); } - final ByteBuffer _res = dispatch_glXChooseVisual(dpy, screen, attribList, Buffers.getDirectBufferByteOffset(attribList), __addr_); + final ByteBuffer _res = dispatch_glXChooseVisual(com.jogamp.common.nio.Buffers.class, dpy, screen, attribList, Buffers.getDirectBufferByteOffset(attribList), __addr_); if (_res == null) return null; return XVisualInfo.create(Buffers.nativeOrder(_res)); } /** Entry point to C language function: <code> XVisualInfo * glXChooseVisual(Display * dpy, int screen, int * attribList); </code> <br>Part of <code>GLX_VERSION_1_X</code> @param attribList a direct only {@link java.nio.IntBuffer} */ - private static native ByteBuffer dispatch_glXChooseVisual(long dpy, int screen, Object attribList, int attribList_byte_offset, long procAddress); + private static native ByteBuffer dispatch_glXChooseVisual(Class clazzBuffers, long dpy, int screen, Object attribList, int attribList_byte_offset, long procAddress); diff --git a/make/config/jogl/glx-x11.cfg b/make/config/jogl/glx-x11.cfg index 17b5fa8d7..d17a22aa3 100644 --- a/make/config/jogl/glx-x11.cfg +++ b/make/config/jogl/glx-x11.cfg @@ -38,8 +38,6 @@ IncludeAs CustomJavaCode GLX glx-CustomJavaCode.java Include glx-headers.cfg IncludeAs CustomCCode glx-CustomCCode.c -ForceStaticInitCode GLX - ArgumentIsString XOpenDisplay 0 Opaque long GLXFBConfig diff --git a/make/config/jogl/wgl-win32.cfg b/make/config/jogl/wgl-win32.cfg index b3db05cec..f480ae4ce 100644 --- a/make/config/jogl/wgl-win32.cfg +++ b/make/config/jogl/wgl-win32.cfg @@ -23,6 +23,9 @@ LocalProcAddressCallingConvention __ALL__ APIENTRY NIOOnly __ALL__ NIODirectOnly __ALL__ +ImmutableAccess RECT +ImmutableAccess PGPU_DEVICE + AllowNonGLExtensions true EmitProcAddressTable true ProcAddressTableClassName WGLProcAddressTable diff --git a/make/config/nativewindow/drm-gbm-lib.cfg b/make/config/nativewindow/drm-gbm-lib.cfg index ad1311ce1..43bbdc8e3 100644 --- a/make/config/nativewindow/drm-gbm-lib.cfg +++ b/make/config/nativewindow/drm-gbm-lib.cfg @@ -28,15 +28,27 @@ ArgumentIsString drmCheckModesettingSupported 0 # ReturnsString XDisplayString # ReturnValueCapacity XRenderFindVisualFormat sizeof(XRenderPictFormat) -ReturnedArrayLength drmModeRes.connectors getCount_connectors() -ReturnedArrayLength drmModeRes.crtcs getCount_crtcs() -ReturnedArrayLength drmModeRes.encoders getCount_encoders() +ImmutableAccess drmModeConnector ReturnedArrayLength drmModeConnector.modes getCount_modes() ReturnedArrayLength drmModeConnector.props getCount_props() ReturnedArrayLength drmModeConnector.prop_values getCount_props() ReturnedArrayLength drmModeConnector.encoders getCount_encoders() + +ImmutableAccess drmModeCrtc + +ImmutableAccess drmModeEncoder + +ImmutableAccess drmModeFB + +ImmutableAccess drmModeModeInfo ReturnsString drmModeModeInfo.name +ImmutableAccess drmModeRes +ReturnedArrayLength drmModeRes.connectors getCount_connectors() +ReturnedArrayLength drmModeRes.crtcs getCount_crtcs() +ReturnedArrayLength drmModeRes.encoders getCount_encoders() + + IgnoreNot ^(drm|DRM_|gbm_|GBM_).+ Ignore drmHandleEvent diff --git a/make/config/nativewindow/jawt-common.cfg b/make/config/nativewindow/jawt-common.cfg index adb6ce49b..4d48c6bf9 100644 --- a/make/config/nativewindow/jawt-common.cfg +++ b/make/config/nativewindow/jawt-common.cfg @@ -15,7 +15,17 @@ ReturnValueCapacity JAWT_DrawingSurface.GetDrawingSurfaceInfo sizeof(JAWT_Drawin IgnoreField JAWT GetComponent IgnoreField JAWT_DrawingSurface target + +ImmutableAccess JAWT_DrawingSurfaceInfo IgnoreField JAWT_DrawingSurfaceInfo platformInfo +IgnoreField JAWT_DrawingSurfaceInfo ds +IgnoreField JAWT_DrawingSurfaceInfo clip + +ImmutableAccess JAWT_Rectangle + +ImmutableAccess JAWT_X11DrawingSurfaceInfo +ImmutableAccess JAWT_Win32DrawingSurfaceInfo +ImmutableAccess JAWT_MacOSXDrawingSurfaceInfo IncludeAs CustomJavaCode JAWT jawt-CustomJavaCode.java diff --git a/make/config/nativewindow/win32-lib.cfg b/make/config/nativewindow/win32-lib.cfg index d4cb15c41..d039d6e90 100644 --- a/make/config/nativewindow/win32-lib.cfg +++ b/make/config/nativewindow/win32-lib.cfg @@ -20,6 +20,14 @@ NIODirectOnly DwmSetWindowAttribute NIODirectOnly GetWindowCompositionAccentPolicy NIODirectOnly SetWindowCompositionAccentPolicy +ImmutableAccess BITMAPINFO +# ImmutableAccess BITMAPINFOHEADER +# ImmutableAccess DWM_BLURBEHIND +# ImmutableAccess MARGINS +# ImmutableAccess PIXELFORMATDESCRIPTOR +ImmutableAccess RECT +ImmutableAccess RGBQUAD + Import com.jogamp.nativewindow.util.Point Import com.jogamp.nativewindow.NativeWindowException Import jogamp.nativewindow.NWJNILibLoader diff --git a/make/config/nativewindow/x11-lib.cfg b/make/config/nativewindow/x11-lib.cfg index 0bbe1c420..65dec9445 100644 --- a/make/config/nativewindow/x11-lib.cfg +++ b/make/config/nativewindow/x11-lib.cfg @@ -24,6 +24,10 @@ Opaque long GLXContext Opaque long GLXFBConfig Opaque long void * +ImmutableAccess XRenderDirectFormat +ImmutableAccess XRenderPictFormat +# ImmutableAccess XVisualInfo + IncludeAs CustomJavaCode X11Lib x11-CustomJavaCode.java ArgumentIsString XOpenDisplay 0 diff --git a/make/config/oculusvr/oculusvr.cfg b/make/config/oculusvr/oculusvr.cfg index b2870e59a..23531c040 100644 --- a/make/config/oculusvr/oculusvr.cfg +++ b/make/config/oculusvr/oculusvr.cfg @@ -9,7 +9,6 @@ Import com.jogamp.common.util.SecurityUtil Import java.security.PrivilegedAction IncludeAs CustomJavaCode OVR oculusvr-ovr-CustomJavaCode.java -ManualStaticInitCall OVR # Provide #includes to native code CustomCCode #define HEADLESS_APP 1 diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java b/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java index ddf5a91f6..d859d3147 100644 --- a/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java +++ b/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java @@ -1,6 +1,6 @@ /* + * Copyright (c) 2010-2023 JogAmp Community. All rights reserved. * Copyright (c) 2003-2005 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 @@ -45,6 +45,7 @@ import com.jogamp.gluegen.ConstantDefinition; import com.jogamp.gluegen.FunctionEmitter; import com.jogamp.gluegen.GlueEmitterControls; import com.jogamp.gluegen.GlueGen; +import com.jogamp.gluegen.JavaCodeUnit; import com.jogamp.gluegen.JavaConfiguration; import com.jogamp.gluegen.JavaEmitter; import com.jogamp.gluegen.JavaMethodBindingEmitter; @@ -58,7 +59,6 @@ import com.jogamp.gluegen.procaddress.ProcAddressJavaMethodBindingEmitter; import com.jogamp.gluegen.runtime.opengl.GLNameResolver; import java.io.IOException; -import java.io.PrintWriter; import java.util.ArrayList; import java.util.IdentityHashMap; import java.util.Iterator; @@ -497,85 +497,84 @@ public class GLEmitter extends ProcAddressEmitter { */ @Override protected void endProcAddressTable() throws Exception { - final PrintWriter w = tableWriter; - - w.println(" @Override"); - w.println(" protected boolean isFunctionAvailableImpl(String functionNameUsr) throws IllegalArgumentException {"); - w.println(" final String functionNameBase = "+GLNameResolver.class.getName()+".normalizeVEN(com.jogamp.gluegen.runtime.opengl.GLNameResolver.normalizeARB(functionNameUsr, true), true);"); - w.println(" final String addressFieldNameBase = \"" + PROCADDRESS_VAR_PREFIX + "\" + functionNameBase;"); - w.println(" final int funcNamePermNum = "+GLNameResolver.class.getName()+".getFuncNamePermutationNumber(functionNameBase);"); - w.println(" final java.lang.reflect.Field addressField = com.jogamp.common.util.SecurityUtil.doPrivileged(new java.security.PrivilegedAction<java.lang.reflect.Field>() {"); - w.println(" public final java.lang.reflect.Field run() {"); - w.println(" java.lang.reflect.Field addressField = null;"); - w.println(" for(int i = 0; i < funcNamePermNum; i++) {"); - w.println(" final String addressFieldName = "+GLNameResolver.class.getName()+".getFuncNamePermutation(addressFieldNameBase, i);"); - w.println(" try {"); - w.println(" addressField = "+tableClassName+".class.getDeclaredField( addressFieldName );"); - w.println(" addressField.setAccessible(true); // we need to read the protected value!"); - w.println(" return addressField;"); - w.println(" } catch (NoSuchFieldException ex) { }"); - w.println(" }"); - w.println(" return null;"); - w.println(" } } );"); - w.println(); - w.println(" if(null==addressField) {"); - w.println(" // The user is calling a bogus function or one which is not"); - w.println(" // runtime linked"); - w.println(" throw new RuntimeException("); - w.println(" \"WARNING: Address field query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +"); - w.println(" \"\\\"; it's either statically linked or address field is not a known \" +"); - w.println(" \"function\");"); - w.println(" } "); - w.println(" try {"); - w.println(" return 0 != addressField.getLong(this);"); - w.println(" } catch (Exception e) {"); - w.println(" throw new RuntimeException("); - w.println(" \"WARNING: Address query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +"); - w.println(" \"\\\"; it's either statically linked or is not a known \" +"); - w.println(" \"function\", e);"); - w.println(" }"); - w.println(" }"); - - w.println(" @Override"); - w.println(" public long getAddressFor(String functionNameUsr) throws SecurityException, IllegalArgumentException {"); - w.println(" SecurityUtil.checkAllLinkPermission();"); - w.println(" final String functionNameBase = "+GLNameResolver.class.getName()+".normalizeVEN(com.jogamp.gluegen.runtime.opengl.GLNameResolver.normalizeARB(functionNameUsr, true), true);"); - w.println(" final String addressFieldNameBase = \"" + PROCADDRESS_VAR_PREFIX + "\" + functionNameBase;"); - w.println(" final int funcNamePermNum = "+GLNameResolver.class.getName()+".getFuncNamePermutationNumber(functionNameBase);"); - w.println(" final java.lang.reflect.Field addressField = com.jogamp.common.util.SecurityUtil.doPrivileged(new java.security.PrivilegedAction<java.lang.reflect.Field>() {"); - w.println(" public final java.lang.reflect.Field run() {"); - w.println(" java.lang.reflect.Field addressField = null;"); - w.println(" for(int i = 0; i < funcNamePermNum; i++) {"); - w.println(" final String addressFieldName = "+GLNameResolver.class.getName()+".getFuncNamePermutation(addressFieldNameBase, i);"); - w.println(" try {"); - w.println(" addressField = "+tableClassName+".class.getDeclaredField( addressFieldName );"); - w.println(" addressField.setAccessible(true); // we need to read the protected value!"); - w.println(" return addressField;"); - w.println(" } catch (NoSuchFieldException ex) { }"); - w.println(" }"); - w.println(" return null;"); - w.println(" } } );"); - w.println(); - w.println(" if(null==addressField) {"); - w.println(" // The user is calling a bogus function or one which is not"); - w.println(" // runtime linked"); - w.println(" throw new RuntimeException("); - w.println(" \"WARNING: Address field query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +"); - w.println(" \"\\\"; it's either statically linked or address field is not a known \" +"); - w.println(" \"function\");"); - w.println(" } "); - w.println(" try {"); - w.println(" return addressField.getLong(this);"); - w.println(" } catch (Exception e) {"); - w.println(" throw new RuntimeException("); - w.println(" \"WARNING: Address query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +"); - w.println(" \"\\\"; it's either statically linked or is not a known \" +"); - w.println(" \"function\", e);"); - w.println(" }"); - w.println(" }"); - - w.println("} // end of class " + tableClassName); - w.flush(); - w.close(); + final JavaCodeUnit u = tableJavaUnit; + + u.emitln(" @Override"); + u.emitln(" protected boolean isFunctionAvailableImpl(String functionNameUsr) throws IllegalArgumentException {"); + u.emitln(" final String functionNameBase = "+GLNameResolver.class.getName()+".normalizeVEN(com.jogamp.gluegen.runtime.opengl.GLNameResolver.normalizeARB(functionNameUsr, true), true);"); + u.emitln(" final String addressFieldNameBase = \"" + PROCADDRESS_VAR_PREFIX + "\" + functionNameBase;"); + u.emitln(" final int funcNamePermNum = "+GLNameResolver.class.getName()+".getFuncNamePermutationNumber(functionNameBase);"); + u.emitln(" final java.lang.reflect.Field addressField = com.jogamp.common.util.SecurityUtil.doPrivileged(new java.security.PrivilegedAction<java.lang.reflect.Field>() {"); + u.emitln(" public final java.lang.reflect.Field run() {"); + u.emitln(" java.lang.reflect.Field addressField = null;"); + u.emitln(" for(int i = 0; i < funcNamePermNum; i++) {"); + u.emitln(" final String addressFieldName = "+GLNameResolver.class.getName()+".getFuncNamePermutation(addressFieldNameBase, i);"); + u.emitln(" try {"); + u.emitln(" addressField = "+tableClassName+".class.getDeclaredField( addressFieldName );"); + u.emitln(" addressField.setAccessible(true); // we need to read the protected value!"); + u.emitln(" return addressField;"); + u.emitln(" } catch (NoSuchFieldException ex) { }"); + u.emitln(" }"); + u.emitln(" return null;"); + u.emitln(" } } );"); + u.emitln(); + u.emitln(" if(null==addressField) {"); + u.emitln(" // The user is calling a bogus function or one which is not"); + u.emitln(" // runtime linked"); + u.emitln(" throw new RuntimeException("); + u.emitln(" \"WARNING: Address field query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +"); + u.emitln(" \"\\\"; it's either statically linked or address field is not a known \" +"); + u.emitln(" \"function\");"); + u.emitln(" } "); + u.emitln(" try {"); + u.emitln(" return 0 != addressField.getLong(this);"); + u.emitln(" } catch (Exception e) {"); + u.emitln(" throw new RuntimeException("); + u.emitln(" \"WARNING: Address query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +"); + u.emitln(" \"\\\"; it's either statically linked or is not a known \" +"); + u.emitln(" \"function\", e);"); + u.emitln(" }"); + u.emitln(" }"); + + u.emitln(" @Override"); + u.emitln(" public long getAddressFor(String functionNameUsr) throws SecurityException, IllegalArgumentException {"); + u.emitln(" SecurityUtil.checkAllLinkPermission();"); + u.emitln(" final String functionNameBase = "+GLNameResolver.class.getName()+".normalizeVEN(com.jogamp.gluegen.runtime.opengl.GLNameResolver.normalizeARB(functionNameUsr, true), true);"); + u.emitln(" final String addressFieldNameBase = \"" + PROCADDRESS_VAR_PREFIX + "\" + functionNameBase;"); + u.emitln(" final int funcNamePermNum = "+GLNameResolver.class.getName()+".getFuncNamePermutationNumber(functionNameBase);"); + u.emitln(" final java.lang.reflect.Field addressField = com.jogamp.common.util.SecurityUtil.doPrivileged(new java.security.PrivilegedAction<java.lang.reflect.Field>() {"); + u.emitln(" public final java.lang.reflect.Field run() {"); + u.emitln(" java.lang.reflect.Field addressField = null;"); + u.emitln(" for(int i = 0; i < funcNamePermNum; i++) {"); + u.emitln(" final String addressFieldName = "+GLNameResolver.class.getName()+".getFuncNamePermutation(addressFieldNameBase, i);"); + u.emitln(" try {"); + u.emitln(" addressField = "+tableClassName+".class.getDeclaredField( addressFieldName );"); + u.emitln(" addressField.setAccessible(true); // we need to read the protected value!"); + u.emitln(" return addressField;"); + u.emitln(" } catch (NoSuchFieldException ex) { }"); + u.emitln(" }"); + u.emitln(" return null;"); + u.emitln(" } } );"); + u.emitln(); + u.emitln(" if(null==addressField) {"); + u.emitln(" // The user is calling a bogus function or one which is not"); + u.emitln(" // runtime linked"); + u.emitln(" throw new RuntimeException("); + u.emitln(" \"WARNING: Address field query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +"); + u.emitln(" \"\\\"; it's either statically linked or address field is not a known \" +"); + u.emitln(" \"function\");"); + u.emitln(" } "); + u.emitln(" try {"); + u.emitln(" return addressField.getLong(this);"); + u.emitln(" } catch (Exception e) {"); + u.emitln(" throw new RuntimeException("); + u.emitln(" \"WARNING: Address query failed for \\\"\" + functionNameBase + \"\\\"/\\\"\" + functionNameUsr +"); + u.emitln(" \"\\\"; it's either statically linked or is not a known \" +"); + u.emitln(" \"function\", e);"); + u.emitln(" }"); + u.emitln(" }"); + + u.emitln("} // end of class " + tableClassName); + u.close(); } } diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureEmitter.java b/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureEmitter.java index c1c2aa12b..7ab6a78d5 100644 --- a/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureEmitter.java +++ b/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureEmitter.java @@ -1,6 +1,6 @@ /* + * Copyright (c) 2010-2023 JogAmp Community. All rights reserved. * Copyright (c) 2006 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 @@ -39,6 +39,7 @@ */ package com.jogamp.gluegen.opengl.nativesig; +import com.jogamp.gluegen.CodeUnit; import com.jogamp.gluegen.FunctionEmitter; import com.jogamp.gluegen.JavaMethodBindingEmitter; import com.jogamp.gluegen.JavaType; @@ -77,14 +78,14 @@ public class NativeSignatureEmitter extends GLEmitter { return res; } - final PrintWriter writer = (getConfig().allStatic() ? javaWriter() : javaImplWriter()); + final CodeUnit unit = (getConfig().allStatic() ? javaUnit() : javaImplUnit()); final List<FunctionEmitter> processed = new ArrayList<FunctionEmitter>(); // First, filter out all emitters going to the "other" (public) writer for (final Iterator<? extends FunctionEmitter> iter = res.iterator(); iter.hasNext();) { final FunctionEmitter emitter = iter.next(); - if (emitter.getDefaultOutput() != writer) { + if (emitter.getUnit() != unit) { processed.add(emitter); iter.remove(); } @@ -116,7 +117,7 @@ public class NativeSignatureEmitter extends GLEmitter { return; } - final PrintWriter writer = (getConfig().allStatic() ? javaWriter() : javaImplWriter()); + final CodeUnit unit = (getConfig().allStatic() ? javaUnit() : javaImplUnit()); // Give ourselves the chance to interpose on the generation of all code to keep things simple final List<JavaMethodBindingEmitter> newEmitters = new ArrayList<JavaMethodBindingEmitter>(); @@ -137,7 +138,7 @@ public class NativeSignatureEmitter extends GLEmitter { // been called with signatureOnly both true and false. if (signatureContainsStrings(binding) && !haveEmitterWithBody(allEmitters)) { // This basically handles glGetString but also any similar methods - final NativeSignatureJavaMethodBindingEmitter javaEmitter = findEmitterWithWriter(allEmitters, writer); + final NativeSignatureJavaMethodBindingEmitter javaEmitter = findEmitterWithUnit(allEmitters, unit); // First, we need to clone this emitter to produce the native // entry point @@ -180,10 +181,10 @@ public class NativeSignatureEmitter extends GLEmitter { return false; } - protected NativeSignatureJavaMethodBindingEmitter findEmitterWithWriter(final List<JavaMethodBindingEmitter> allEmitters, final PrintWriter writer) { + protected NativeSignatureJavaMethodBindingEmitter findEmitterWithUnit(final List<JavaMethodBindingEmitter> allEmitters, final CodeUnit unit) { for (final JavaMethodBindingEmitter jemitter : allEmitters) { final NativeSignatureJavaMethodBindingEmitter emitter = (NativeSignatureJavaMethodBindingEmitter)jemitter; - if (emitter.getDefaultOutput() == writer) { + if (emitter.getUnit() == unit) { return emitter; } } diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureJavaMethodBindingEmitter.java b/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureJavaMethodBindingEmitter.java index 3478538d6..696a4b95c 100644 --- a/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureJavaMethodBindingEmitter.java +++ b/src/jogl/classes/com/jogamp/gluegen/opengl/nativesig/NativeSignatureJavaMethodBindingEmitter.java @@ -1,6 +1,6 @@ /* + * Copyright (c) 2010-2023 JogAmp Community. All rights reserved. * Copyright (c) 2006 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 @@ -49,8 +49,6 @@ import com.jogamp.gluegen.opengl.GLEmitter; import com.jogamp.gluegen.opengl.GLJavaMethodBindingEmitter; import com.jogamp.gluegen.procaddress.ProcAddressJavaMethodBindingEmitter; -import java.io.PrintWriter; - /** Review: This Package/Class is not used and subject to be deleted. */ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBindingEmitter { @@ -67,35 +65,35 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding } @Override - protected void emitSignature(final PrintWriter writer) { - writer.print(getBaseIndentString()); - emitNativeSignatureAnnotation(writer); - super.emitSignature(writer); + protected void emitSignature() { + unit.emit(getBaseIndentString()); + emitNativeSignatureAnnotation(); + super.emitSignature(); } - protected void emitNativeSignatureAnnotation(final PrintWriter writer) { + protected void emitNativeSignatureAnnotation() { if (hasModifier(JavaMethodBindingEmitter.NATIVE)) { // Emit everything as a leaf for now // FIXME: make this configurable - writer.print("@NativeSignature(\"l"); + unit.emit("@NativeSignature(\"l"); final MethodBinding binding = getBinding(); if (callThroughProcAddress) { - writer.print("p"); + unit.emit("p"); } - writer.print("("); + unit.emit("("); if (callThroughProcAddress) { - writer.print("P"); + unit.emit("P"); } for (int i = 0; i < binding.getNumArguments(); i++) { - emitNativeSignatureElement(writer, binding.getJavaArgumentType(i), binding.getCArgumentType(i), i); + emitNativeSignatureElement(binding.getJavaArgumentType(i), binding.getCArgumentType(i), i); } - writer.print(")"); - emitNativeSignatureElement(writer, binding.getJavaReturnType(), binding.getCReturnType(), -1); - writer.println("\")"); + unit.emit(")"); + emitNativeSignatureElement(binding.getJavaReturnType(), binding.getCReturnType(), -1); + unit.emitln("\")"); } } - protected void emitNativeSignatureElement(final PrintWriter writer, final JavaType type, final Type cType, final int index) { + protected void emitNativeSignatureElement(final JavaType type, final Type cType, final int index) { if (type.isVoid()) { if (index > 0) { throw new InternalError("Error parsing arguments -- void should not be seen aside from argument 0"); @@ -104,29 +102,29 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding } if (type.isNIOBuffer()) { - writer.print("A"); + unit.emit("A"); } else if (type.isPrimitiveArray()) { - writer.print("MO"); + unit.emit("MO"); } else if (type.isPrimitive()) { final Class<?> clazz = type.getJavaClass(); - if (clazz == Byte.TYPE) { writer.print("B"); } - else if (clazz == Character.TYPE) { writer.print("C"); } - else if (clazz == Double.TYPE) { writer.print("D"); } - else if (clazz == Float.TYPE) { writer.print("F"); } - else if (clazz == Integer.TYPE) { writer.print("I"); } + if (clazz == Byte.TYPE) { unit.emit("B"); } + else if (clazz == Character.TYPE) { unit.emit("C"); } + else if (clazz == Double.TYPE) { unit.emit("D"); } + else if (clazz == Float.TYPE) { unit.emit("F"); } + else if (clazz == Integer.TYPE) { unit.emit("I"); } else if (clazz == Long.TYPE) { // See if this is intended to be a pointer at the C level if (cType.isPointer()) { - writer.print("A"); + unit.emit("A"); } else { - writer.print("J"); + unit.emit("J"); } } - else if (clazz == Short.TYPE) { writer.print("S"); } - else if (clazz == Boolean.TYPE) { writer.print("Z"); } + else if (clazz == Short.TYPE) { unit.emit("S"); } + else if (clazz == Boolean.TYPE) { unit.emit("Z"); } else throw new InternalError("Unhandled primitive type " + clazz); } else if (type.isString()) { - writer.print("A"); + unit.emit("A"); } else { throw new RuntimeException("Type not yet handled: " + type); } @@ -145,17 +143,17 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding } @Override - protected void emitPreCallSetup(final MethodBinding binding, final PrintWriter writer) { - super.emitPreCallSetup(binding, writer); + protected void emitPreCallSetup(final MethodBinding binding) { + super.emitPreCallSetup(binding); for (int i = 0; i < binding.getNumArguments(); i++) { final JavaType type = binding.getJavaArgumentType(i); if (type.isNIOBuffer() && !useNIODirectOnly ) { // Emit declarations for variables holding primitive arrays as type Object // We don't know 100% sure we're going to use these at this point in the code, though - writer.println(" Object " + getNIOBufferArrayName(i) + " = (_direct ? null : Buffers.getArray(" + + unit.emitln(" Object " + getNIOBufferArrayName(i) + " = (_direct ? null : Buffers.getArray(" + getArgumentName(i) + "));"); } else if (type.isString()) { - writer.println(" long " + binding.getArgumentName(i) + "_c_str = BuffersInternal.newCString(" + binding.getArgumentName(i) + ");"); + unit.emitln(" long " + binding.getArgumentName(i) + "_c_str = BuffersInternal.newCString(" + binding.getArgumentName(i) + ");"); } // FIXME: going to need more of these for Buffer[] and String[], at least } @@ -166,14 +164,14 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding } @Override - protected int emitArguments(final PrintWriter writer) + protected int emitArguments() { boolean needComma = false; int numEmitted = 0; if (callThroughProcAddress) { if (changeNameAndArguments) { - writer.print("long procAddress"); + unit.emit("long procAddress"); ++numEmitted; needComma = true; } @@ -181,12 +179,12 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding if (isPrivateNativeMethod() && binding.hasContainingType()) { if (needComma) { - writer.print(", "); + unit.emit(", "); } // Always emit outgoing "this" argument - writer.print("long "); - writer.print(javaThisArgumentName()); + unit.emit("long "); + unit.emit(javaThisArgumentName()); ++numEmitted; needComma = true; } @@ -210,20 +208,20 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding } if (needComma) { - writer.print(", "); + unit.emit(", "); } if (isPrivateNativeMethod() && (isForDirectBufferImplementation() && type.isNIOBuffer() || type.isString())) { // Direct Buffers and Strings go out as longs - writer.print("long"); + unit.emit("long"); // FIXME: will need more tests here to handle other constructs like String and direct Buffer arrays } else { - writer.print(erasedTypeString(type, false)); + unit.emit(erasedTypeString(type, false)); } - writer.print(" "); - writer.print(getArgumentName(i)); + unit.emit(" "); + unit.emit(getArgumentName(i)); ++numEmitted; needComma = true; @@ -231,46 +229,46 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding // Add Buffer and array index offset arguments after each associated argument if (isForIndirectBufferAndArrayImplementation()) { if (type.isNIOBuffer()) { - writer.print(", int " + byteOffsetArgName(i)); + unit.emit(", int " + byteOffsetArgName(i)); } else if (type.isNIOBufferArray()) { - writer.print(", int[] " + + unit.emit(", int[] " + byteOffsetArrayArgName(i)); } } // Add offset argument after each primitive array if (type.isPrimitiveArray()) { - writer.print(", int " + offsetArgName(i)); + unit.emit(", int " + offsetArgName(i)); } } return numEmitted; } @Override - protected void emitReturnVariableSetupAndCall(final MethodBinding binding, final PrintWriter writer) { - writer.print(" "); + protected void emitReturnVariableSetupAndCall(final MethodBinding binding) { + unit.emit(" "); final JavaType returnType = binding.getJavaReturnType(); boolean needsResultAssignment = false; if (!returnType.isVoid()) { if (returnType.isCompoundTypeWrapper() || returnType.isNIOByteBuffer()) { - writer.println("final java.nio.ByteBuffer _res;"); + unit.emitln("final java.nio.ByteBuffer _res;"); needsResultAssignment = true; } else if (returnType.isArrayOfCompoundTypeWrappers()) { - writer.println("final java.nio.ByteBuffer[] _res;"); + unit.emitln("final java.nio.ByteBuffer[] _res;"); needsResultAssignment = true; } else if (returnType.isString() || returnType.isNIOByteBuffer()) { - writer.print("final "); - writer.print(returnType); - writer.println(" _res;"); + unit.emit("final "); + unit.emit(returnType.toString()); + unit.emitln(" _res;"); needsResultAssignment = true; } else { // Always assign to "_res" variable so we can clean up // outgoing String arguments, for example - writer.print("final "); - emitReturnType(writer); - writer.println(" _res;"); + unit.emit("final "); + emitReturnType(); + unit.emitln(" _res;"); needsResultAssignment = true; } } @@ -278,21 +276,21 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding if (binding.signatureCanUseIndirectNIO() && !useNIODirectOnly) { // Must generate two calls for this gated on whether the NIO // buffers coming in are all direct or indirect - writer.println("if (_direct) {"); - writer.print (" "); + unit.emitln("if (_direct) {"); + unit.emit (" "); } if (needsResultAssignment) { - writer.print(" _res = "); + unit.emit(" _res = "); if (returnType.isString()) { - writer.print("BuffersInternal.newJavaString("); + unit.emit("BuffersInternal.newJavaString("); } else if (returnType.isNIOByteBuffer()) { - writer.print("BuffersInternal.newDirectByteBuffer("); + unit.emit("BuffersInternal.newDirectByteBuffer("); } } else { - writer.print(" "); + unit.emit(" "); if (!returnType.isVoid()) { - writer.print("return "); + unit.emit("return "); } } @@ -304,48 +302,48 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding // Only one call being made in this body, going to indirect // buffer / array entry point - emitCall(binding, writer); + emitCall(binding); if (returnType.isString() || returnType.isNIOByteBuffer()) { - writer.print(")"); + unit.emit(")"); } - writer.print(";"); - writer.println(); + unit.emit(";"); + unit.emitln(); } else { - emitCall(binding, writer); + emitCall(binding); if (returnType.isString() || returnType.isNIOByteBuffer()) { - writer.print(")"); + unit.emit(")"); } - writer.print(";"); + unit.emit(";"); } if (binding.signatureCanUseIndirectNIO() && !useNIODirectOnly) { // Must generate two calls for this gated on whether the NIO // buffers coming in are all direct or indirect - writer.println(); - writer.println(" } else {"); - writer.print (" "); + unit.emitln(); + unit.emitln(" } else {"); + unit.emit (" "); if (needsResultAssignment) { - writer.print(" _res = "); + unit.emit(" _res = "); } else { - writer.print(" "); + unit.emit(" "); if (!returnType.isVoid()) { - writer.print("return "); + unit.emit("return "); } } - emitCall(binding, writer); - writer.print(";"); - writer.println(); - writer.println(" }"); + emitCall(binding); + unit.emit(";"); + unit.emitln(); + unit.emitln(" }"); } else { - writer.println(); + unit.emitln(); } - emitPrologueOrEpilogue(epilogue, writer); + emitPrologueOrEpilogue(epilogue); if (needsResultAssignment) { - emitCallResultReturn(binding, writer); + emitCallResultReturn(binding); } } - protected int emitCallArguments(final MethodBinding binding, final PrintWriter writer, final boolean direct) { + protected int emitCallArguments(final MethodBinding binding, final boolean direct) { // Note that we override this completely because we both need to // move the potential location of the outgoing proc address as // well as change the way we pass out Buffers, arrays, Strings, etc. @@ -354,7 +352,7 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding int numArgsEmitted = 0; if (callThroughProcAddress) { - writer.print("__addr_"); + unit.emit("__addr_"); needComma = true; ++numArgsEmitted; } @@ -362,9 +360,9 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding if (binding.hasContainingType()) { // Emit this pointer assert(binding.getContainingType().isCompoundTypeWrapper()); - writer.print("BuffersInternal.getDirectBufferAddress("); - writer.print("getBuffer()"); - writer.print(")"); + unit.emit("BuffersInternal.getDirectBufferAddress("); + unit.emit("getBuffer()"); + unit.emit(")"); needComma = true; ++numArgsEmitted; } @@ -383,76 +381,76 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding } if (needComma) { - writer.print(", "); + unit.emit(", "); } if (type.isCompoundTypeWrapper()) { - writer.print("BuffersInternal.getDirectBufferAddress("); - writer.print("(("); + unit.emit("BuffersInternal.getDirectBufferAddress("); + unit.emit("(("); } if (type.isNIOBuffer()) { if (!direct) { - writer.print(getNIOBufferArrayName(i)); + unit.emit(getNIOBufferArrayName(i)); } else { - writer.print("BuffersInternal.getDirectBufferAddress("); - writer.print(getArgumentName(i)); - writer.print(")"); + unit.emit("BuffersInternal.getDirectBufferAddress("); + unit.emit(getArgumentName(i)); + unit.emit(")"); } } else { - writer.print(getArgumentName(i)); + unit.emit(getArgumentName(i)); } if (type.isCompoundTypeWrapper()) { - writer.print(" == null) ? null : "); - writer.print(getArgumentName(i)); - writer.print(".getBuffer())"); - writer.print(")"); + unit.emit(" == null) ? null : "); + unit.emit(getArgumentName(i)); + unit.emit(".getBuffer())"); + unit.emit(")"); } if (type.isNIOBuffer()) { if (direct) { - writer.print("+ Buffers.getDirectBufferByteOffset(" + getArgumentName(i) + ")"); + unit.emit("+ Buffers.getDirectBufferByteOffset(" + getArgumentName(i) + ")"); } else { - writer.print(", BuffersInternal.arrayBaseOffset(" + + unit.emit(", BuffersInternal.arrayBaseOffset(" + getNIOBufferArrayName(i) + ") + Buffers.getIndirectBufferByteOffset(" + getArgumentName(i) + ")"); } } else if (type.isNIOBufferArray()) { - writer.print(", " + byteOffsetArrayArgName(i)); + unit.emit(", " + byteOffsetArrayArgName(i)); } // Add Array offset parameter for primitive arrays if (type.isPrimitiveArray()) { - writer.print(", "); - writer.print("BuffersInternal.arrayBaseOffset(" + getArgumentName(i) + ") + "); + unit.emit(", "); + unit.emit("BuffersInternal.arrayBaseOffset(" + getArgumentName(i) + ") + "); if(type.isFloatArray()) { - writer.print("Buffers.SIZEOF_FLOAT * "); + unit.emit("Buffers.SIZEOF_FLOAT * "); } else if(type.isDoubleArray()) { - writer.print("Buffers.SIZEOF_DOUBLE * "); + unit.emit("Buffers.SIZEOF_DOUBLE * "); } else if(type.isByteArray()) { - writer.print("1 * "); + unit.emit("1 * "); } else if(type.isLongArray()) { - writer.print("Buffers.SIZEOF_LONG * "); + unit.emit("Buffers.SIZEOF_LONG * "); } else if(type.isShortArray()) { - writer.print("Buffers.SIZEOF_SHORT * "); + unit.emit("Buffers.SIZEOF_SHORT * "); } else if(type.isIntArray()) { - writer.print("Buffers.SIZEOF_INT * "); + unit.emit("Buffers.SIZEOF_INT * "); } else { throw new GlueGenException("Unsupported type for calculating array offset argument for " + getArgumentName(i) + "-- error occurred while processing Java glue code for " + binding.getCSymbol().getAliasedString(), binding.getCSymbol().getASTLocusTag()); } - writer.print(offsetArgName(i)); + unit.emit(offsetArgName(i)); } if (type.isString()) { - writer.print("_c_str"); + unit.emit("_c_str"); } if (type.isCompoundTypeWrapper()) { - writer.print(")"); + unit.emit(")"); } needComma = true; @@ -462,17 +460,17 @@ public class NativeSignatureJavaMethodBindingEmitter extends GLJavaMethodBinding } @Override - protected void emitCallResultReturn(final MethodBinding binding, final PrintWriter writer) { + protected void emitCallResultReturn(final MethodBinding binding) { for (int i = 0; i < binding.getNumArguments(); i++) { final JavaType type = binding.getJavaArgumentType(i); if (type.isString()) { - writer.println(";"); - writer.println(" BuffersInternal.freeCString(" + binding.getArgumentName(i) + "_c_str);"); + unit.emitln(";"); + unit.emitln(" BuffersInternal.freeCString(" + binding.getArgumentName(i) + "_c_str);"); } // FIXME: will need more of these cleanups for things like Buffer[] and String[] (see above) } - super.emitCallResultReturn(binding, writer); + super.emitCallResultReturn(binding); } @Override |