From 9a764b3d331335f1e8557cf7b7f84b8cdf224854 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Tue, 22 Feb 2005 13:59:33 +0000 Subject: [PATCH] Linux: moved handle allocations to native --- build.xml | 1 + .../opengl/LinuxContextImplementation.java | 8 +--- src/java/org/lwjgl/opengl/LinuxPeerInfo.java | 5 +- ..._lwjgl_opengl_LinuxContextImplementation.c | 14 +++--- .../linux/org_lwjgl_opengl_LinuxPeerInfo.c | 48 +++++++++++++++++++ 5 files changed, 61 insertions(+), 15 deletions(-) create mode 100644 src/native/linux/org_lwjgl_opengl_LinuxPeerInfo.c diff --git a/build.xml b/build.xml index aaeb83cd..fd07664d 100644 --- a/build.xml +++ b/build.xml @@ -559,6 +559,7 @@ + diff --git a/src/java/org/lwjgl/opengl/LinuxContextImplementation.java b/src/java/org/lwjgl/opengl/LinuxContextImplementation.java index 613ad687..7d2efe42 100644 --- a/src/java/org/lwjgl/opengl/LinuxContextImplementation.java +++ b/src/java/org/lwjgl/opengl/LinuxContextImplementation.java @@ -43,20 +43,16 @@ import org.lwjgl.BufferUtils; * @version $Revision$ */ final class LinuxContextImplementation implements ContextImplementation { - private final static int HANDLE_SIZE = 64; - private static PeerInfo getCurrentPeerInfo() { return Context.getCurrentContext().getPeerInfo(); } public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException { - ByteBuffer handle = BufferUtils.createByteBuffer(HANDLE_SIZE); LinuxDisplay.lockAWT(); try { ByteBuffer peer_handle = peer_info.lockAndGetHandle(); try { - nCreate(peer_handle, handle, shared_context_handle); - return handle; + return nCreate(peer_handle, shared_context_handle); } finally { peer_info.unlock(); } @@ -65,7 +61,7 @@ final class LinuxContextImplementation implements ContextImplementation { } } - private static native void nCreate(ByteBuffer peer_handle, ByteBuffer context_handle, ByteBuffer shared_context_handle) throws LWJGLException; + private static native ByteBuffer nCreate(ByteBuffer peer_handle, ByteBuffer shared_context_handle) throws LWJGLException; public void swapBuffers() throws LWJGLException { PeerInfo current_peer_info = getCurrentPeerInfo(); diff --git a/src/java/org/lwjgl/opengl/LinuxPeerInfo.java b/src/java/org/lwjgl/opengl/LinuxPeerInfo.java index b333a8d7..ff3d406a 100644 --- a/src/java/org/lwjgl/opengl/LinuxPeerInfo.java +++ b/src/java/org/lwjgl/opengl/LinuxPeerInfo.java @@ -44,9 +44,8 @@ import org.lwjgl.Sys; * @version $Revision$ */ abstract class LinuxPeerInfo extends PeerInfo { - private static final int PEER_HANDLE_SIZE = 64; - public LinuxPeerInfo() { - super(BufferUtils.createByteBuffer(PEER_HANDLE_SIZE)); + super(createHandle()); } + private static native ByteBuffer createHandle(); } diff --git a/src/native/linux/org_lwjgl_opengl_LinuxContextImplementation.c b/src/native/linux/org_lwjgl_opengl_LinuxContextImplementation.c index 54a43526..6193fd2c 100644 --- a/src/native/linux/org_lwjgl_opengl_LinuxContextImplementation.c +++ b/src/native/linux/org_lwjgl_opengl_LinuxContextImplementation.c @@ -99,18 +99,19 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nSetVSyn } } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nCreate - (JNIEnv *env , jclass clazz, jobject peer_handle, jobject context_handle, jobject shared_context_handle) { - if ((*env)->GetDirectBufferCapacity(env, context_handle) < sizeof(X11Context)) { - throwException(env, "Handle buffer not large enough"); - return; +JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nCreate + (JNIEnv *env , jclass clazz, jobject peer_handle, jobject shared_context_handle) { + jobject context_handle = newJavaManagedByteBuffer(env, sizeof(X11Context)); + if (context_handle == NULL) { + throwException(env, "Could not allocate handle buffer"); + return NULL; } X11PeerInfo *peer_info = (*env)->GetDirectBufferAddress(env, peer_handle); X11Context *context_info = (*env)->GetDirectBufferAddress(env, context_handle); if (!extgl_InitGLX(env, peer_info->display, peer_info->screen)) { throwException(env, "Could not initialize GLX"); - return; + return NULL; } GLXContext shared_context = NULL; if (shared_context_handle != NULL) { @@ -122,6 +123,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nCreate } else { createContextGLX(env, peer_info, context_info, shared_context); } + return context_handle; } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nDestroy diff --git a/src/native/linux/org_lwjgl_opengl_LinuxPeerInfo.c b/src/native/linux/org_lwjgl_opengl_LinuxPeerInfo.c new file mode 100644 index 00000000..cb35c4d3 --- /dev/null +++ b/src/native/linux/org_lwjgl_opengl_LinuxPeerInfo.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * $Id$ + * + * @author elias_naur + * @version $Revision$ + */ + +#include +#include "org_lwjgl_opengl_LinuxPeerInfo.h" +#include "context.h" +#include "common_tools.h" + +JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxPeerInfo_createHandle + (JNIEnv *env, jclass clazz) { + return newJavaManagedByteBuffer(env, sizeof(X11PeerInfo)); +}