Linux: Don't use the SUN specific getScreenFromDevice in LinuxAWTCanvasPeerInfo. This avoids garbage creation per frame and avoids one bit of SUN JRE dependency.

This commit is contained in:
Elias Naur 2006-10-20 11:51:34 +00:00
parent dc4a31e799
commit 8698cf68f3
2 changed files with 31 additions and 26 deletions

View File

@ -45,20 +45,25 @@ import org.lwjgl.LWJGLUtil;
final class LinuxAWTGLCanvasPeerInfo extends LinuxPeerInfo {
private final AWTGLCanvas canvas;
private final AWTSurfaceLock awt_surface = new AWTSurfaceLock();
private int screen = -1;
public LinuxAWTGLCanvasPeerInfo(AWTGLCanvas canvas) {
this.canvas = canvas;
}
protected void doLockAndInitHandle() throws LWJGLException {
int screen = -1;
try {
screen = LinuxCanvasImplementation.getScreenFromDevice(canvas.getGraphicsConfiguration().getDevice());
} catch (LWJGLException e) {
LWJGLUtil.log("Got exception while trying to determine screen: " + e);
ByteBuffer surface_handle = awt_surface.lockAndGetHandle(canvas);
if (screen == -1) {
try {
screen = getScreenFromSurfaceInfo(surface_handle);
} catch (LWJGLException e) {
LWJGLUtil.log("Got exception while trying to determine screen: " + e);
screen = 0;
}
}
nInitHandle(screen, awt_surface.lockAndGetHandle(canvas), getHandle());
nInitHandle(screen, surface_handle, getHandle());
}
private static native int getScreenFromSurfaceInfo(ByteBuffer surface_handle) throws LWJGLException;
private static native void nInitHandle(int screen, ByteBuffer surface_buffer, ByteBuffer peer_info_handle) throws LWJGLException;
protected void doUnlock() throws LWJGLException {

View File

@ -47,33 +47,33 @@
#include "org_lwjgl_opengl_LinuxAWTGLCanvasPeerInfo.h"
#include "context.h"
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxAWTGLCanvasPeerInfo_getScreenFromSurfaceInfo
(JNIEnv *env, jclass clazz, jobject lock_buffer_handle) {
const AWTSurfaceLock *awt_lock = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle);
// Get the platform-specific drawing info
JAWT_X11DrawingSurfaceInfo *dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)awt_lock->dsi->platformInfo;
XVisualInfo template;
int num_infos;
template.visualid = dsi_x11->visualID;
template.depth = dsi_x11->depth;
XVisualInfo *vis_info = XGetVisualInfo(dsi_x11->display, VisualIDMask | VisualDepthMask, &template, &num_infos);
if (vis_info == NULL) {
throwException(env, "Could not determine screen");
return -1;
}
int screen = vis_info[0].screen;
XFree(vis_info);
return screen;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxAWTGLCanvasPeerInfo_nInitHandle
(JNIEnv *env, jclass clazz, int screen, jobject lock_buffer_handle, jobject peer_info_handle) {
if ((*env)->GetDirectBufferCapacity(env, peer_info_handle) < sizeof(X11PeerInfo)) {
throwException(env, "PeerInfo handle buffer not large enough");
return;
}
const AWTSurfaceLock *awt_lock = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle);
X11PeerInfo *peer_info = (X11PeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle);
// Get the platform-specific drawing info
JAWT_X11DrawingSurfaceInfo *dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)awt_lock->dsi->platformInfo;
// If we couldn't get a screen from java side, attempt to determine a sane screen
// from the information we do have, namely the visualid and the depth
if (screen == -1) {
XVisualInfo template;
int num_infos;
template.visualid = dsi_x11->visualID;
template.depth = dsi_x11->depth;
XVisualInfo *vis_info = XGetVisualInfo(dsi_x11->display, VisualIDMask | VisualDepthMask, &template, &num_infos);
if (vis_info == NULL) {
throwException(env, "Could not determine screen");
return;
}
screen = vis_info[0].screen;
XFree(vis_info);
}
peer_info->display = dsi_x11->display;
peer_info->screen = screen;
peer_info->drawable = dsi_x11->drawable;