From aef35ae0ed48b821c5ed333d6f7e464721adaa43 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 27 May 2005 11:50:13 +0000 Subject: [PATCH] Linux AWT: in case we're not on a SUN jdk, try to determine values instead of bombing out. This should help us compile and run on gcj --- .../opengl/LinuxAWTGLCanvasPeerInfo.java | 8 ++++++- .../opengl/LinuxCanvasImplementation.java | 21 ++++++++++++------- .../opengl/Win32CanvasImplementation.java | 2 +- ...rg_lwjgl_opengl_LinuxAWTGLCanvasPeerInfo.c | 16 ++++++++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java b/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java index ce1fa7fe..04ceb006 100644 --- a/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java +++ b/src/java/org/lwjgl/opengl/LinuxAWTGLCanvasPeerInfo.java @@ -34,6 +34,7 @@ package org.lwjgl.opengl; import java.nio.ByteBuffer; import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; /** * $Id$ @@ -50,7 +51,12 @@ final class LinuxAWTGLCanvasPeerInfo extends LinuxPeerInfo { } protected void doLockAndInitHandle() throws LWJGLException { - int screen = LinuxCanvasImplementation.getScreenFromDevice(canvas.getGraphicsConfiguration().getDevice()); + int screen = -1; + try { + screen = LinuxCanvasImplementation.getScreenFromDevice(canvas.getGraphicsConfiguration().getDevice()); + } catch (LWJGLException e) { + LWJGLUtil.log("Got exception while trying to determine screen: " + e); + } nInitHandle(screen, awt_surface.lockAndGetHandle(canvas), getHandle()); } private static native void nInitHandle(int screen, ByteBuffer surface_buffer, ByteBuffer peer_info_handle) throws LWJGLException; diff --git a/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java b/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java index 79f7a09b..de73ff21 100644 --- a/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java +++ b/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java @@ -36,6 +36,7 @@ import java.awt.GraphicsDevice; import java.lang.reflect.Method; import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; /** * $Id$ @@ -74,15 +75,19 @@ final class LinuxCanvasImplementation implements AWTCanvasImplementation { * @return The GraphicsConfiguration corresponding to a visual that matches the pixel format. */ public GraphicsConfiguration findConfiguration(GraphicsDevice device, PixelFormat pixel_format) throws LWJGLException { - int screen = getScreenFromDevice(device); - int visual_id_matching_format = findVisualIDFromFormat(screen, pixel_format); - GraphicsConfiguration[] configurations = device.getConfigurations(); - for (int i = 0; i < configurations.length; i++) { - int visual_id = getVisualIDFromConfiguration(configurations[i]); - if (visual_id == visual_id_matching_format) - return configurations[i]; + try { + int screen = getScreenFromDevice(device); + int visual_id_matching_format = findVisualIDFromFormat(screen, pixel_format); + GraphicsConfiguration[] configurations = device.getConfigurations(); + for (int i = 0; i < configurations.length; i++) { + int visual_id = getVisualIDFromConfiguration(configurations[i]); + if (visual_id == visual_id_matching_format) + return configurations[i]; + } + } catch (LWJGLException e) { + LWJGLUtil.log("Got exception while trying to determine configuration: " + e); } - throw new LWJGLException("Could not find the matching GraphicsConfiguration to visual id"); + return null; // In case we failed to locate the visual, or if we're not on a SUN JDK } private static int findVisualIDFromFormat(int screen, PixelFormat pixel_format) throws LWJGLException { diff --git a/src/java/org/lwjgl/opengl/Win32CanvasImplementation.java b/src/java/org/lwjgl/opengl/Win32CanvasImplementation.java index 8cb228a9..557731b2 100644 --- a/src/java/org/lwjgl/opengl/Win32CanvasImplementation.java +++ b/src/java/org/lwjgl/opengl/Win32CanvasImplementation.java @@ -58,7 +58,7 @@ final class Win32CanvasImplementation implements AWTCanvasImplementation { */ public GraphicsConfiguration findConfiguration(GraphicsDevice device, PixelFormat pixel_format) throws LWJGLException { /* - * It seems like the best way is to simply return null and let + * It seems like the best way is to simply return null and * use SetPixelFormat in JNI later. */ return null; diff --git a/src/native/linux/org_lwjgl_opengl_LinuxAWTGLCanvasPeerInfo.c b/src/native/linux/org_lwjgl_opengl_LinuxAWTGLCanvasPeerInfo.c index 28c04a07..199a0c3a 100644 --- a/src/native/linux/org_lwjgl_opengl_LinuxAWTGLCanvasPeerInfo.c +++ b/src/native/linux/org_lwjgl_opengl_LinuxAWTGLCanvasPeerInfo.c @@ -60,6 +60,22 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxAWTGLCanvasPeerInfo_nInitHandl // 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(peer_info->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;