diff options
author | Kenneth Russel <[email protected]> | 2004-06-19 01:58:40 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2004-06-19 01:58:40 +0000 |
commit | 8f1783018b2df30d1ba59866cfde9f884da5ad97 (patch) | |
tree | 30a815946edbf281d927a7b607bff18f9a6294f9 /src/net/java/games/jogl/impl/SingleThreadedWorkaround.java | |
parent | 8fc1f6b579fa953abf7627df1198bf1677b9e54f (diff) |
This putback attempts to address the following issues:
Issue 59: GLContext Leak
Issue 67: Java/Jogl app hangs some systems, not others, during reshape.
Issue 69: Error on window resize
Issue 89: Losing Backbuffer when Resizing/Moving a window
The primary change is to support handing off of the display()
implementation to the AWT event queue thread via a new class called
SingleThreadedWorkaround in the impl package. This was done to cause
the AWT's reshape code to execute on the same thread as all other
OpenGL rendering without changing the threading model (e.g., Animator
and the ability to manually call display()) visible to the end user.
This set of changes appears to work around the problems seen on ATI
cards with random corruption when resizing animating windows due to
multithreading bugs in the drivers. More testing by a larger community
will confirm this fix. Currently the workaround is enabled by default
on ATI cards.
A secondary but related change is to properly destroy the OpenGL
context when a heavyweight component is removed from its container.
In order to implement the above workaround, it was necessary to
override addNotify and removeNotify to properly track whether
GLCanvases were realized; at that point it was a fairly small step to
properly delete and recreate OpenGL contexts. The previous heuristics
which attempted to determine when a heavyweight had been realized have
been removed. A new demo, TestContextDestruction, exercises the new
functionality. It does still appear to exhibit resource leaks,
however; removing and re-adding the GLCanvas from its parent multiple
times causes the system to eventually slow down significantly. More
work is needed in this area. However, the demo does now execute as
opposed to throwing an exception which was the previous behavior.
The current code has been tested on Windows on NVidia hardware with
all existing demos with the workaround both enabled and disabled, and
on ATI hardware with the existing compatible demos with the workaround
enabled. The new abstract method in GLContext, destroyImpl(), has been
implemented but not yet tested on X11 and Mac OS X.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@132 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games/jogl/impl/SingleThreadedWorkaround.java')
-rwxr-xr-x | src/net/java/games/jogl/impl/SingleThreadedWorkaround.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/net/java/games/jogl/impl/SingleThreadedWorkaround.java b/src/net/java/games/jogl/impl/SingleThreadedWorkaround.java new file mode 100755 index 000000000..ca6485ea2 --- /dev/null +++ b/src/net/java/games/jogl/impl/SingleThreadedWorkaround.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2003 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 + * MIDROSYSTEMS, 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 net.java.games.jogl.impl; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** Encapsulates the workaround of running all display operations on + the AWT event queue thread for the purposes of working around + problems seen primarily on ATI cards when rendering into a surface + that is simultaneously being resized by the event queue thread */ + +public class SingleThreadedWorkaround { + private static boolean ATI_WORKAROUND = false; + // If the user specified the workaround's system property (either + // true or false), don't let the automatic detection have any effect + private static boolean systemPropertySpecified = false; + + static { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String workaround = System.getProperty("ATI_WORKAROUND"); + if (workaround != null) { + systemPropertySpecified = true; + ATI_WORKAROUND = Boolean.valueOf(workaround).booleanValue(); + } + printWorkaroundNotice(); + return null; + } + }); + } + + public static void shouldDoWorkaround() { + if (!systemPropertySpecified) { + ATI_WORKAROUND = true; + printWorkaroundNotice(); + } + } + + public static boolean doWorkaround() { + return ATI_WORKAROUND; + } + + private static void printWorkaroundNotice() { + if (ATI_WORKAROUND) { + System.err.println("Using ATI workaround of dispatching display() on event thread"); + } + } +} |