Linux: moved handle allocations to native
This commit is contained in:
parent
47814d58f4
commit
9a764b3d33
|
@ -559,6 +559,7 @@
|
||||||
<!-- platform specific classes -->
|
<!-- platform specific classes -->
|
||||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/linux" force="yes">
|
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/linux" force="yes">
|
||||||
<class name="org.lwjgl.opengl.LinuxDisplay" />
|
<class name="org.lwjgl.opengl.LinuxDisplay" />
|
||||||
|
<class name="org.lwjgl.opengl.LinuxPeerInfo" />
|
||||||
<class name="org.lwjgl.opengl.LinuxPbufferPeerInfo" />
|
<class name="org.lwjgl.opengl.LinuxPbufferPeerInfo" />
|
||||||
<class name="org.lwjgl.opengl.LinuxDisplayPeerInfo" />
|
<class name="org.lwjgl.opengl.LinuxDisplayPeerInfo" />
|
||||||
<class name="org.lwjgl.opengl.LinuxAWTGLCanvasPeerInfo" />
|
<class name="org.lwjgl.opengl.LinuxAWTGLCanvasPeerInfo" />
|
||||||
|
|
|
@ -43,20 +43,16 @@ import org.lwjgl.BufferUtils;
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
*/
|
*/
|
||||||
final class LinuxContextImplementation implements ContextImplementation {
|
final class LinuxContextImplementation implements ContextImplementation {
|
||||||
private final static int HANDLE_SIZE = 64;
|
|
||||||
|
|
||||||
private static PeerInfo getCurrentPeerInfo() {
|
private static PeerInfo getCurrentPeerInfo() {
|
||||||
return Context.getCurrentContext().getPeerInfo();
|
return Context.getCurrentContext().getPeerInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException {
|
public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException {
|
||||||
ByteBuffer handle = BufferUtils.createByteBuffer(HANDLE_SIZE);
|
|
||||||
LinuxDisplay.lockAWT();
|
LinuxDisplay.lockAWT();
|
||||||
try {
|
try {
|
||||||
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
|
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
|
||||||
try {
|
try {
|
||||||
nCreate(peer_handle, handle, shared_context_handle);
|
return nCreate(peer_handle, shared_context_handle);
|
||||||
return handle;
|
|
||||||
} finally {
|
} finally {
|
||||||
peer_info.unlock();
|
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 {
|
public void swapBuffers() throws LWJGLException {
|
||||||
PeerInfo current_peer_info = getCurrentPeerInfo();
|
PeerInfo current_peer_info = getCurrentPeerInfo();
|
||||||
|
|
|
@ -44,9 +44,8 @@ import org.lwjgl.Sys;
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
*/
|
*/
|
||||||
abstract class LinuxPeerInfo extends PeerInfo {
|
abstract class LinuxPeerInfo extends PeerInfo {
|
||||||
private static final int PEER_HANDLE_SIZE = 64;
|
|
||||||
|
|
||||||
public LinuxPeerInfo() {
|
public LinuxPeerInfo() {
|
||||||
super(BufferUtils.createByteBuffer(PEER_HANDLE_SIZE));
|
super(createHandle());
|
||||||
}
|
}
|
||||||
|
private static native ByteBuffer createHandle();
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,18 +99,19 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nSetVSyn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nCreate
|
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nCreate
|
||||||
(JNIEnv *env , jclass clazz, jobject peer_handle, jobject context_handle, jobject shared_context_handle) {
|
(JNIEnv *env , jclass clazz, jobject peer_handle, jobject shared_context_handle) {
|
||||||
if ((*env)->GetDirectBufferCapacity(env, context_handle) < sizeof(X11Context)) {
|
jobject context_handle = newJavaManagedByteBuffer(env, sizeof(X11Context));
|
||||||
throwException(env, "Handle buffer not large enough");
|
if (context_handle == NULL) {
|
||||||
return;
|
throwException(env, "Could not allocate handle buffer");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
X11PeerInfo *peer_info = (*env)->GetDirectBufferAddress(env, peer_handle);
|
X11PeerInfo *peer_info = (*env)->GetDirectBufferAddress(env, peer_handle);
|
||||||
X11Context *context_info = (*env)->GetDirectBufferAddress(env, context_handle);
|
X11Context *context_info = (*env)->GetDirectBufferAddress(env, context_handle);
|
||||||
|
|
||||||
if (!extgl_InitGLX(env, peer_info->display, peer_info->screen)) {
|
if (!extgl_InitGLX(env, peer_info->display, peer_info->screen)) {
|
||||||
throwException(env, "Could not initialize GLX");
|
throwException(env, "Could not initialize GLX");
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
GLXContext shared_context = NULL;
|
GLXContext shared_context = NULL;
|
||||||
if (shared_context_handle != NULL) {
|
if (shared_context_handle != NULL) {
|
||||||
|
@ -122,6 +123,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nCreate
|
||||||
} else {
|
} else {
|
||||||
createContextGLX(env, peer_info, context_info, shared_context);
|
createContextGLX(env, peer_info, context_info, shared_context);
|
||||||
}
|
}
|
||||||
|
return context_handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nDestroy
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nDestroy
|
||||||
|
|
|
@ -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 <elias_naur@users.sourceforge.net>
|
||||||
|
* @version $Revision$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
#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));
|
||||||
|
}
|
Loading…
Reference in New Issue