summaryrefslogtreecommitdiffstats
path: root/src/classes
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2006-02-16 02:49:30 +0000
committerKenneth Russel <[email protected]>2006-02-16 02:49:30 +0000
commit945e2ae3d234815b43f83049c9d597cb61585797 (patch)
treee5967c06c09bddd9068e0807573da34d6dfa2fa0 /src/classes
parentf50877b19f5a3cb4deb1b26395ce357f3ebfd3f0 (diff)
Fixed problems with lack of hardware acceleration on Linux
distributions using DRI drivers. Hacked around limitations of the current DRI implementation by manually dlopen'ing libGL.so.1; avoids changing glue code generation for core OpenGL 1.1 routines which do not otherwise need to be called through function pointers on any platform. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@614 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes')
-rw-r--r--src/classes/com/sun/opengl/impl/NativeLibLoader.java19
-rw-r--r--src/classes/com/sun/opengl/impl/x11/DRIHack.java109
-rw-r--r--src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java5
-rwxr-xr-xsrc/classes/com/sun/opengl/util/JOGLAppletLauncher.java34
4 files changed, 164 insertions, 3 deletions
diff --git a/src/classes/com/sun/opengl/impl/NativeLibLoader.java b/src/classes/com/sun/opengl/impl/NativeLibLoader.java
index 1a3d5c277..9331b2f72 100644
--- a/src/classes/com/sun/opengl/impl/NativeLibLoader.java
+++ b/src/classes/com/sun/opengl/impl/NativeLibLoader.java
@@ -55,6 +55,7 @@ public class NativeLibLoader {
private static volatile boolean loadedCore = false;
private static volatile boolean loadedAWTImpl = false;
+ private static volatile boolean loadedDRIHack = false;
public static void loadCore() {
if (doLoading && !loadedCore) {
@@ -104,4 +105,22 @@ public class NativeLibLoader {
}
}
}
+
+ // See DRIHack.java in com/sun/opengl/impl/x11/ for description of
+ // why this is needed
+ public static void loadDRIHack() {
+ if (doLoading && !loadedDRIHack) {
+ synchronized (NativeLibLoader.class) {
+ if (!loadedDRIHack) {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ System.loadLibrary("jogl_drihack");
+ return null;
+ }
+ });
+ loadedDRIHack = true;
+ }
+ }
+ }
+ }
}
diff --git a/src/classes/com/sun/opengl/impl/x11/DRIHack.java b/src/classes/com/sun/opengl/impl/x11/DRIHack.java
new file mode 100644
index 000000000..181210982
--- /dev/null
+++ b/src/classes/com/sun/opengl/impl/x11/DRIHack.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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 Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * You acknowledge that this software is not designed or intended for use
+ * in the design, construction, operation or maintenance of any nuclear
+ * facility.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.sun.opengl.impl.x11;
+
+import java.io.*;
+import java.security.*;
+import com.sun.opengl.impl.*;
+
+/**
+ * Helper class for working around problems with open-source DRI
+ * drivers. In the current DRI implementation it is required that the
+ * symbols in libGL.so.1.2 be globally visible to be accessible from
+ * other libraries that are dynamically loaded by the implementation.
+ * Applications may typically satisfy this need either by linking
+ * against libGL.so on the command line (-lGL) or by dlopen'ing
+ * libGL.so.1.2 with the RTLD_GLOBAL flag. The JOGL implementation
+ * links against libGL on all platforms rather than forcing all OpenGL
+ * entry points to be called through a function pointer. This allows
+ * the JOGL library to link directly to core 1.1 OpenGL entry points
+ * like glVertex3f, while calling through function pointers for entry
+ * points from later OpenGL versions as well as from
+ * extensions. However, because libjogl.so (which links against
+ * libGL.so) is loaded by the JVM, and because the JVM implicitly uses
+ * RTLD_LOCAL in the implementation of System.loadLibrary(), this
+ * means via transitivity that the symbols for libGL.so have only
+ * RTLD_LOCAL visibility to the rest of the application, so the DRI
+ * drivers can not find the symbols required. <P>
+ *
+ * There are at least two possible solutions. One would be to change
+ * the JOGL implementation to call through function pointers uniformly
+ * so that it does not need to link against libGL.so. This is
+ * possible, but requires changes to GlueGen and also is not really
+ * necessary in any other situation than with the DRI drivers. Another
+ * solution is to force the first load of libGL.so.1.2 to be done
+ * dynamically with RTLD_GLOBAL before libjogl.so is loaded and causes
+ * libGL.so.1.2 to be loaded again. This requires the C APIs dlopen
+ * and dlclose to be made available before libjogl.so is loaded. This
+ * is the solution currently chosen and is called the "DRI hack"
+ * because again it is needed only in this situation.
+ */
+
+public class DRIHack {
+ public static native long dlopen(String name);
+ public static native int dlclose(long handle);
+
+ private static boolean driHackNeeded;
+ private static long libGLHandle;
+
+ public static void begin() {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ driHackNeeded = new File("/usr/lib/dri").exists();
+ return null;
+ }
+ });
+
+ if (driHackNeeded) {
+ System.err.println("Beginning DRI hack");
+
+ NativeLibLoader.loadDRIHack();
+ libGLHandle = dlopen("/usr/lib/libGL.so.1");
+ }
+ }
+
+ public static void end() {
+ if (libGLHandle != 0) {
+ System.err.println("Ending DRI hack");
+
+ dlclose(libGLHandle);
+ }
+ }
+}
diff --git a/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java b/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java
index c7b0e1a0c..aa26f133e 100644
--- a/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java
+++ b/src/classes/com/sun/opengl/impl/x11/X11GLDrawableFactory.java
@@ -57,8 +57,13 @@ public class X11GLDrawableFactory extends GLDrawableFactoryImpl {
private static boolean isLinuxAMD64;
static {
+ // See DRIHack.java for an explanation of why this is necessary
+ DRIHack.begin();
+
NativeLibLoader.loadCore();
+ DRIHack.end();
+
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
String os = System.getProperty("os.name").toLowerCase();
diff --git a/src/classes/com/sun/opengl/util/JOGLAppletLauncher.java b/src/classes/com/sun/opengl/util/JOGLAppletLauncher.java
index 7a9f8ab74..6db8d39be 100755
--- a/src/classes/com/sun/opengl/util/JOGLAppletLauncher.java
+++ b/src/classes/com/sun/opengl/util/JOGLAppletLauncher.java
@@ -181,6 +181,10 @@ public class JOGLAppletLauncher extends Applet {
// The signatures of these native libraries are checked before
// installing them.
private String[] nativeLibNames;
+ // Whether the "DRI hack" native library is present and whether we
+ // therefore might need to run the DRIHack during loading of the
+ // native libraries
+ private boolean driHackPresent;
/** The applet we have to start */
private Applet subApplet;
@@ -524,6 +528,9 @@ public class JOGLAppletLauncher extends Applet {
JarEntry entry = (JarEntry) e.nextElement();
if (nativeLibInfo.matchesNativeLib(entry.getName())) {
list.add(entry.getName());
+ if (entry.getName().indexOf("jogl_drihack") >= 0) {
+ driHackPresent = true;
+ }
}
}
if (list.isEmpty()) {
@@ -615,9 +622,33 @@ public class JOGLAppletLauncher extends Applet {
public void run() {
displayMessage("Loading native libraries");
+ // disable JOGL loading from elsewhere
+ com.sun.opengl.impl.NativeLibLoader.disableLoading();
+
+ Class driHackClass = null;
+ if (driHackPresent) {
+ // Load DRI hack library and run the DRI hack itself
+ loadLibrary(nativeLibDir, "jogl_drihack");
+ try {
+ driHackClass = Class.forName("com.sun.opengl.impl.x11.DRIHack");
+ driHackClass.getMethod("begin", new Class[] {}).invoke(null, new Object[] {});
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
// Load core JOGL native library
loadLibrary(nativeLibDir, "jogl");
+ if (driHackPresent) {
+ // End DRI hack
+ try {
+ driHackClass.getMethod("end", new Class[] {}).invoke(null, new Object[] {});
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
if (!nativeLibInfo.isMacOS()) { // borrowed from NativeLibLoader
// Must pre-load JAWT on all non-Mac platforms to
// ensure references from jogl_awt shared object
@@ -638,9 +669,6 @@ public class JOGLAppletLauncher extends Applet {
// Load AWT-specific native code
loadLibrary(nativeLibDir, "jogl_awt");
- // disable JOGL loading from elsewhere
- com.sun.opengl.impl.NativeLibLoader.disableLoading();
-
displayMessage("Starting applet " + subAppletDisplayName);
// start the subapplet