diff options
Diffstat (limited to 'src')
4 files changed, 125 insertions, 14 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/awt/GLCanvas.java b/src/jogl/classes/com/jogamp/opengl/awt/GLCanvas.java index 735a2a21c..97a3321d5 100644 --- a/src/jogl/classes/com/jogamp/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/com/jogamp/opengl/awt/GLCanvas.java @@ -86,6 +86,8 @@ import com.jogamp.opengl.GLSharedContextSetter; import com.jogamp.opengl.Threading; import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.os.Platform; +import com.jogamp.common.os.Platform.OSType; import com.jogamp.common.util.VersionUtil; import com.jogamp.common.util.awt.AWTEDTExecutor; import com.jogamp.common.util.locks.LockFactory; @@ -169,6 +171,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing private static final boolean DEBUG = Debug.debug("GLCanvas"); + private static JAWTUtil.BackgroundEraseControl backgroundEraseControl = new JAWTUtil.BackgroundEraseControl(); + private final RecursiveLock lock = LockFactory.createRecursiveLock(); private final GLDrawableHelper helper = new GLDrawableHelper(); private volatile GLDrawableImpl drawable; // volatile: avoid locking for read-only access @@ -589,7 +593,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing */ // before native peer is valid: X11 - JAWTUtil.disableBackgroundErase(this); + if( OSType.WINDOWS != Platform.getOSType() ) { + backgroundEraseControl.disable(this); + } final GraphicsDevice awtDevice; if(null==awtDeviceReq) { @@ -614,7 +620,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing super.addNotify(); // after native peer is valid: Windows - JAWTUtil.disableBackgroundErase(this); + if( OSType.WINDOWS == Platform.getOSType() ) { + backgroundEraseControl.disable(this); + } createJAWTDrawableAndContext(); diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java index 86de6e30d..f3c3da286 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java @@ -109,7 +109,7 @@ public class JAWTUtil { // default initialization to null, false Method awtLockMID; Method awtUnlockMID; - Method disableBackgroundEraseMID; + Method stkDisableBackgroundEraseMID; boolean ok; } private static class GraphicsDeviceData { @@ -117,7 +117,6 @@ public class JAWTUtil { // default initialization to null, false Method getScaleFactorMID; Method getCGDisplayIDMIDOnOSX; - boolean ok; } /** @@ -381,8 +380,8 @@ public class JAWTUtil { d.awtLockMID.setAccessible(true); d.awtUnlockMID = sunToolkitClass.getDeclaredMethod("awtUnlock"); d.awtUnlockMID.setAccessible(true); - d.disableBackgroundEraseMID = sunToolkitClass.getDeclaredMethod("disableBackgroundErase", java.awt.Component.class); - d.disableBackgroundEraseMID.setAccessible(true); + d.stkDisableBackgroundEraseMID = sunToolkitClass.getDeclaredMethod("disableBackgroundErase", java.awt.Component.class); + d.stkDisableBackgroundEraseMID.setAccessible(true); d.ok=true; } catch (final Exception e) { // Either not a Sun JDK or the interfaces have changed since [Java 1.4.2 / 1.5 -> Java 11] @@ -394,7 +393,7 @@ public class JAWTUtil { }}); }}); stkAWTLockMID = std.awtLockMID; stkAWTUnlockMID = std.awtUnlockMID; - stkDisableBackgroundEraseMID = std.disableBackgroundEraseMID; + stkDisableBackgroundEraseMID = std.stkDisableBackgroundEraseMID; boolean _hasSunToolkitAWTLock = false; if ( std.ok ) { try { @@ -489,7 +488,7 @@ public class JAWTUtil { } if (DEBUG) { - System.err.println("JAWTUtil: Has sun.awt.SunToolkit: awtLock/awtUnlock " + hasSTKAWTLock + ", disableBackgroundErase "+(null!=stkDisableBackgroundEraseMID)); + System.err.println("JAWTUtil: Has sun.awt.SunToolkit: awtLock/awtUnlock " + hasSTKAWTLock + ", stkDisableBackgroundErase "+(null!=stkDisableBackgroundEraseMID)); System.err.println("JAWTUtil: Has Java2D " + j2dExist); System.err.println("JAWTUtil: Is headless " + headlessMode); final int hints = ( null != desktophints ) ? desktophints.size() : 0 ; @@ -604,19 +603,27 @@ public class JAWTUtil { * @param component * @return {@code true} if available and successful, otherwise {@code false} */ - public static boolean disableBackgroundErase(final java.awt.Component component) { + public static boolean disableBackgroundEraseSTK(final java.awt.Component component) { if( null != stkDisableBackgroundEraseMID ) { try { stkDisableBackgroundEraseMID.invoke(component.getToolkit(), component); + if( DEBUG ) { + System.err.println(getThreadName()+dbe_msg+" OK"); + } return true; } catch (final Exception e) { if( DEBUG ) { - ExceptionUtils.dumpThrowable("JAWTUtil", e); + System.err.println(getThreadName()+dbe_msg+" failed, error "+e); + ExceptionUtils.dumpThrowable(dbe_msg, e); } } } + if( DEBUG ) { + System.err.println(getThreadName()+dbe_msg+" failed, no method"); + } return false; } + private static final String dbe_msg = ": java.awt.Component: STK disableBackgroundErase"; /** * Queries the Monitor's display ID of the given device @@ -800,5 +807,85 @@ public class JAWTUtil { return NativeWindowFactory.createScreen(adevice, AWTGraphicsScreen.findScreenIndex(awtComp.getGraphicsConfiguration().getDevice())); } + + /** + * Disables the AWT's erasing of this Canvas's background on Windows in Java SE 6. + * <p> + * Utilize this class as a static instance within your AWT Canvas override. + * </p> + * <p> + * Implementation also calls {@link JAWTUtil#disableBackgroundEraseSTK(java.awt.Component)} just in case. + * </p> + * <p> + * This internal API is not available in previous releases, + * but the system property {@code -Dsun.awt.noerasebackground=true} + * can be specified to get similar results globally in previous releases. + * </p> + */ + public static class BackgroundEraseControl { + private boolean disableBackgroundEraseInitialized = false; + private Method disableBackgroundEraseMethod = null; + private static final String msg = ": java.awt.Canvas: TK disableBackgroundErase"; + + /** + * Disables the AWT's erasing of this Canvas's background on Windows in Java SE 6. + * <p> + * Method also calls {@link JAWTUtil#disableBackgroundEraseSTK(java.awt.Component)} just in case. + * </p> + */ + public boolean disable(final java.awt.Canvas canvas) { + if (!disableBackgroundEraseInitialized) { + try { + SecurityUtil.doPrivileged(new PrivilegedAction<Object>() { + @Override + public Object run() { + try { + Class<?> clazz = canvas.getToolkit().getClass(); + while (clazz != null && disableBackgroundEraseMethod == null) { + try { + disableBackgroundEraseMethod = + clazz.getDeclaredMethod("disableBackgroundErase", + new Class[] { java.awt.Canvas.class }); + disableBackgroundEraseMethod.setAccessible(true); + } catch (final Exception e) { + clazz = clazz.getSuperclass(); + } + } + } catch (final Exception e) { + } + return null; + } + }); + } catch (final Exception e) { + } + disableBackgroundEraseInitialized = true; + if(DEBUG) { + System.err.println(getThreadName()+msg+" method found: "+ + (null!=disableBackgroundEraseMethod)); + } + } + boolean res = false; + if (disableBackgroundEraseMethod != null) { + Throwable t=null; + try { + disableBackgroundEraseMethod.invoke(canvas.getToolkit(), new Object[] { canvas }); + res = true; + } catch (final Exception e) { + t = e; + } + if(DEBUG) { + System.err.println(getThreadName()+msg+" res "+res+", error: "+t); + if( null != t ) { + ExceptionUtils.dumpThrowable(msg, t); + } + } + } else if(DEBUG) { + System.err.println(getThreadName()+msg+" failed, no method"); + } + JAWTUtil.disableBackgroundEraseSTK(canvas); + return res; + } + } + } diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index 783bc6857..fc885e591 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -69,6 +69,8 @@ import jogamp.newt.driver.DriverClearFocus; import jogamp.opengl.awt.AWTTilePainter; import com.jogamp.common.ExceptionUtils; +import com.jogamp.common.os.Platform; +import com.jogamp.common.os.Platform.OSType; import com.jogamp.common.util.awt.AWTEDTExecutor; import com.jogamp.nativewindow.awt.AWTGraphicsConfiguration; import com.jogamp.nativewindow.awt.AWTPrintLifecycle; @@ -100,6 +102,8 @@ import com.jogamp.opengl.util.TileRenderer; public class NewtCanvasAWT extends java.awt.Canvas implements NativeWindowHolder, WindowClosingProtocol, OffscreenLayerOption, AWTPrintLifecycle { public static final boolean DEBUG = Debug.debug("Window"); + private static JAWTUtil.BackgroundEraseControl backgroundEraseControl = new JAWTUtil.BackgroundEraseControl(); + private final Object sync = new Object(); private volatile JAWTWindow jawtWindow = null; // the JAWTWindow presentation of this AWT Canvas, bound to the 'drawable' lifecycle private boolean isApplet = false; @@ -589,7 +593,9 @@ public class NewtCanvasAWT extends java.awt.Canvas implements NativeWindowHolder * This code order also allows recreation, ie re-adding the GLCanvas. */ // before native peer is valid: X11 - JAWTUtil.disableBackgroundErase(this); + if( OSType.WINDOWS != Platform.getOSType() ) { + backgroundEraseControl.disable(this); + } // Query AWT GraphicsDevice from parent tree, default final GraphicsConfiguration gc = super.getGraphicsConfiguration(); @@ -607,7 +613,9 @@ public class NewtCanvasAWT extends java.awt.Canvas implements NativeWindowHolder super.addNotify(); // after native peer is valid: Windows - JAWTUtil.disableBackgroundErase(this); + if( OSType.WINDOWS == Platform.getOSType() ) { + backgroundEraseControl.disable(this); + } synchronized(sync) { determineIfApplet(); diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java index b81bd7544..11eb1dba0 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java +++ b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java @@ -39,6 +39,8 @@ import java.awt.Graphics; import java.awt.GraphicsDevice; import java.awt.GraphicsConfiguration; +import com.jogamp.common.os.Platform; +import com.jogamp.common.os.Platform.OSType; import com.jogamp.nativewindow.AbstractGraphicsDevice; import com.jogamp.nativewindow.AbstractGraphicsScreen; import com.jogamp.nativewindow.CapabilitiesChooser; @@ -59,6 +61,8 @@ import jogamp.nativewindow.jawt.JAWTUtil; @SuppressWarnings("serial") public class AWTCanvas extends Canvas { + private static JAWTUtil.BackgroundEraseControl backgroundEraseControl = new JAWTUtil.BackgroundEraseControl(); + private final WindowDriver driver; private final CapabilitiesImmutable capabilities; private final CapabilitiesChooser chooser; @@ -121,7 +125,9 @@ public class AWTCanvas extends Canvas { public void addNotify() { // before native peer is valid: X11 - JAWTUtil.disableBackgroundErase(this); + if( OSType.WINDOWS != Platform.getOSType() ) { + backgroundEraseControl.disable(this); + } /** * 'super.addNotify()' determines the GraphicsConfiguration, @@ -146,7 +152,9 @@ public class AWTCanvas extends Canvas { super.addNotify(); // after native peer is valid: Windows - JAWTUtil.disableBackgroundErase(this); + if( OSType.WINDOWS == Platform.getOSType() ) { + backgroundEraseControl.disable(this); + } { jawtWindow = (JAWTWindow) NativeWindowFactory.getNativeWindow(this, awtConfig); |