From 3ab518e90eb4cf82bcb8b990d337a5e4a531136b Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 18 Aug 2012 11:46:01 +0200 Subject: GLProfile/NativeWindowFactory: Remove deprecated argument 'firstUIActionOnProcess' of initSingleton() method The notion of changing the threading behavior of native initialization was deprecated for over a year. The code still contained the bits and pieces, i.e. whether X11Util.initSingletion() is invoked before or after optional AWT initialization. This condition has been removed now and behavior is uniform, i.e. X11Util.initSingletion() is invoked after optional AWT initialization. - Removed GLProfile.initSingleton(boolean firstUIActionOnProcess), use remaining GLProfile.initSingleton() - Removed NativeWindowFactory.isFirstUIActionOnProcess() - Changed NativeWindowFactory.initSingleton(boolean firstUIActionOnProcess) to NativeWindowFactory.initSingleton() --- src/jogl/classes/javax/media/opengl/GLProfile.java | 54 +++++++++------------- .../media/nativewindow/NativeWindowFactory.java | 46 +++++------------- .../nativewindow/NativeWindowFactoryImpl.java | 2 +- .../jogamp/nativewindow/macosx/OSXUtil.java | 12 ++--- .../jogamp/nativewindow/windows/GDIUtil.java | 15 +++--- .../classes/jogamp/nativewindow/x11/X11Util.java | 13 +++--- src/newt/classes/com/jogamp/newt/NewtFactory.java | 2 +- .../classes/com/jogamp/newt/util/MainThread.java | 2 +- .../test/junit/newt/TestRemoteWindow01NEWT.java | 2 +- .../test/junit/newt/TestScreenMode00NEWT.java | 2 +- .../test/junit/newt/TestScreenMode00bNEWT.java | 2 +- .../opengl/test/junit/newt/TestWindows01NEWT.java | 2 +- 12 files changed, 57 insertions(+), 97 deletions(-) (limited to 'src') diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index 1e10dc9a6..513ccd101 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -101,29 +101,29 @@ public class GLProfile { /** * Static initialization of JOGL. + * *

- * The parameter firstUIActionOnProcess has an impact on concurrent locking,
- * see {@link javax.media.nativewindow.NativeWindowFactory#initSingleton(boolean) NativeWindowFactory.initSingleton(firstUIActionOnProcess)}. + * This method shall not need to be called for other reasons than having a defined initialization sequence. *

- *

- * Applications using this method may place it's call before any other UI invocation - * in the main class's static block or within the main function. - * In such case, applications may pass firstUIActionOnProcess=true to use native toolkit locking.

- *

- * RCP Application (Applet's, Webstart, Netbeans, ..) using JOGL are not be able to initialize JOGL - * before the first UI action. - * In such case you shall pass firstUIActionOnProcess=false.

+ * *

* In case this method is not invoked, GLProfile is initialized implicit by - * the first call to {@link #getDefault()}, {@link #get(java.lang.String)} passing firstUIActionOnProcess=false. + * the first call to {@link #getDefault()}, {@link #get(java.lang.String)}. *

- * - * @param firstUIActionOnProcess Should be true if called before the first UI action of the running program, - * otherwise false. * - * @deprecated Use {@link #initSingleton()}. This method is subject to be removed in future versions of JOGL. + *

+ * To initialize JOGL at startup ASAP, this method may be invoked in the main class's + * static initializer block, in the static main() method or in the Applet init() method. + *

+ * + *

+ * Since JOGL's initialization is complex and involves multi threading, it is not recommended + * to be have it invoked on the AWT EDT thread. In case all JOGL usage is performed + * on the AWT EDT, invoke this method outside the AWT EDT - see above. + *

+ * */ - public static void initSingleton(final boolean firstUIActionOnProcess) { + public static void initSingleton() { final boolean justInitialized; initLock.lock(); try { @@ -131,7 +131,7 @@ public class GLProfile { initialized = true; justInitialized = true; if(DEBUG) { - System.err.println("GLProfile.initSingleton(firstUIActionOnProcess: "+firstUIActionOnProcess+") - thread "+Thread.currentThread().getName()); + System.err.println("GLProfile.initSingleton() - thread "+Thread.currentThread().getName()); Thread.dumpStack(); } @@ -171,7 +171,7 @@ public class GLProfile { } JNILibLoaderBase.addNativeJarLibs(classesFromJavaJars, "-all", new String[] { "-noawt", "-mobile", "-core" } ); } - initProfilesForDefaultDevices(firstUIActionOnProcess); + initProfilesForDefaultDevices(); return null; } }); @@ -188,17 +188,6 @@ public class GLProfile { } } - /** - * Static initialization of JOGL. - * - *

- * This method shall not need to be called for other reasons than having a defined initialization sequence. - *

- */ - public static void initSingleton() { - GLProfile.initSingleton(false); - } - /** * Trigger eager initialization of GLProfiles for the given device, * in case it isn't done yet. @@ -1411,11 +1400,10 @@ public class GLProfile { /** * Tries the profiles implementation and native libraries. */ - private static void initProfilesForDefaultDevices(boolean firstUIActionOnProcess) { - NativeWindowFactory.initSingleton(firstUIActionOnProcess); + private static void initProfilesForDefaultDevices() { + NativeWindowFactory.initSingleton(); if(DEBUG) { - System.err.println("GLProfile.init firstUIActionOnProcess: "+ firstUIActionOnProcess - + ", thread: " + Thread.currentThread().getName()); + System.err.println("GLProfile.init - thread: " + Thread.currentThread().getName()); System.err.println(VersionUtil.getPlatformInfo()); System.err.println(GlueGenVersion.getInstance()); System.err.println(NativeWindowVersion.getInstance()); diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java index 6faa9890c..94f5d753c 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java @@ -99,7 +99,6 @@ public abstract class NativeWindowFactory { private static Constructor x11JAWTToolkitLockConstructor; private static Class x11ToolkitLockClass; private static Constructor x11ToolkitLockConstructor; - private static boolean isFirstUIActionOnProcess; private static boolean requiresToolkitLock; /** Creates a new NativeWindowFactory instance. End users do not @@ -138,9 +137,7 @@ public abstract class NativeWindowFactory { static boolean initialized = false; - private static void initSingletonNativeImpl(final boolean firstUIActionOnProcess, final ClassLoader cl) { - isFirstUIActionOnProcess = firstUIActionOnProcess; - + private static void initSingletonNativeImpl(final ClassLoader cl) { final String clazzName; if( TYPE_X11.equals(nativeWindowingTypePure) ) { clazzName = X11UtilClassName; @@ -152,9 +149,7 @@ public abstract class NativeWindowFactory { clazzName = null; } if( null != clazzName ) { - ReflectionUtil.callStaticMethod(clazzName, "initSingleton", - new Class[] { boolean.class }, - new Object[] { new Boolean(firstUIActionOnProcess) }, cl ); + ReflectionUtil.callStaticMethod(clazzName, "initSingleton", null, null, cl ); final Boolean res = (Boolean) ReflectionUtil.callStaticMethod(clazzName, "requiresToolkitLock", null, null, cl); requiresToolkitLock = res.booleanValue(); @@ -166,24 +161,13 @@ public abstract class NativeWindowFactory { /** * Static one time initialization of this factory.
* This initialization method must be called once by the program or utilizing modules! - *

- * The parameter firstUIActionOnProcess has an impact on concurrent locking: - *

- *

- * @param firstUIActionOnProcess Should be true if called before the first UI action of the running program, - * otherwise false. */ - public static synchronized void initSingleton(final boolean firstUIActionOnProcess) { + public static synchronized void initSingleton() { if(!initialized) { initialized = true; if(DEBUG) { - System.err.println(Thread.currentThread().getName()+" - NativeWindowFactory.initSingleton("+firstUIActionOnProcess+")"); + System.err.println(Thread.currentThread().getName()+" - NativeWindowFactory.initSingleton()"); } final ClassLoader cl = NativeWindowFactory.class.getClassLoader(); @@ -197,10 +181,6 @@ public abstract class NativeWindowFactory { nativeWindowingTypeCustom = tmp; } - if(firstUIActionOnProcess) { - // X11 initialization before possible AWT initialization - initSingletonNativeImpl(true, cl); - } isAWTAvailable = false; // may be set to true below if( Platform.AWT_AVAILABLE && @@ -248,10 +228,13 @@ public abstract class NativeWindowFactory { } } } - if(!firstUIActionOnProcess) { - // X11 initialization after possible AWT initialization - initSingletonNativeImpl(false, cl); - } + + // X11 initialization after possible AWT initialization + // This is performed post AWT initialization, allowing AWT to complete the same, + // which may have been triggered before NativeWindow initialization. + // This way behavior is more uniforms across configurations (Applet/RCP, applications, ..). + initSingletonNativeImpl(cl); + registeredFactories = Collections.synchronizedMap(new HashMap, NativeWindowFactory>()); // register our default factory -> NativeWindow @@ -276,7 +259,6 @@ public abstract class NativeWindowFactory { } if(DEBUG) { - System.err.println("NativeWindowFactory firstUIActionOnProcess "+firstUIActionOnProcess); System.err.println("NativeWindowFactory requiresToolkitLock "+requiresToolkitLock); System.err.println("NativeWindowFactory isAWTAvailable "+isAWTAvailable+", defaultFactory "+factory); } @@ -301,12 +283,6 @@ public abstract class NativeWindowFactory { } } - /** @return true if initialized with {@link #initSingleton(boolean) initSingleton(firstUIActionOnProcess==true)}, - otherwise false. */ - public static boolean isFirstUIActionOnProcess() { - return isFirstUIActionOnProcess; - } - /** @return true if the underlying toolkit requires locking, otherwise false. */ public static boolean requiresToolkitLock() { return requiresToolkitLock; diff --git a/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java index 9e18439db..2c2a627a4 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java +++ b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java @@ -90,7 +90,7 @@ public class NativeWindowFactoryImpl extends NativeWindowFactory { // Assume Linux, Solaris, etc. Should probably test for these explicitly. windowClassName = "jogamp.nativewindow.jawt.x11.X11JAWTWindow"; } else { - throw new IllegalArgumentException("OS " + Platform.getOSName() + " not yet supported"); + throw new IllegalArgumentException("Native windowing type " + windowingType + " (custom) not yet supported, platform reported native windowing type: "+getNativeWindowType(false)); } nativeWindowConstructor = ReflectionUtil.getConstructor( diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index 894084fce..f5f735051 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -38,20 +38,18 @@ public class OSXUtil { private static boolean isInit = false; private static final boolean DEBUG = Debug.debug("OSXUtil"); - public static synchronized void initSingleton(boolean firstX11ActionOnProcess) { + public static synchronized void initSingleton() { if(!isInit) { + if(DEBUG) { + System.out.println("OSXUtil.initSingleton()"); + } if(!NWJNILibLoader.loadNativeWindow("macosx")) { throw new NativeWindowException("NativeWindow MacOSX native library load error."); } if( !initIDs0() ) { throw new NativeWindowException("MacOSX: Could not initialized native stub"); - } - - if(DEBUG) { - System.out.println("OSX.isFirstX11ActionOnProcess: "+firstX11ActionOnProcess); - } - + } isInit = true; } } diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java b/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java index d17a1898c..fda1649b6 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java @@ -41,24 +41,21 @@ public class GDIUtil { private static RegisteredClassFactory dummyWindowClassFactory; private static boolean isInit = false; - public static synchronized void initSingleton(boolean firstX11ActionOnProcess) { + public static synchronized void initSingleton() { if(!isInit) { synchronized(X11Util.class) { if(!isInit) { - isInit = true; + if(DEBUG) { + System.out.println("GDI.initSingleton()"); + } if(!NWJNILibLoader.loadNativeWindow("win32")) { throw new NativeWindowException("NativeWindow Windows native library load error."); } - if( !initIDs0() ) { throw new NativeWindowException("GDI: Could not initialized native stub"); } - - if(DEBUG) { - System.out.println("GDI.isFirstX11ActionOnProcess: "+firstX11ActionOnProcess); - } - - dummyWindowClassFactory = new RegisteredClassFactory(dummyWindowClassNameBase, getDummyWndProc0()); + dummyWindowClassFactory = new RegisteredClassFactory(dummyWindowClassNameBase, getDummyWndProc0()); + isInit = true; } } } diff --git a/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java b/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java index 7b46a1df0..860238649 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java +++ b/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java @@ -95,18 +95,20 @@ public class X11Util { private static Object setX11ErrorHandlerLock = new Object(); - @SuppressWarnings("unused") - public static void initSingleton(final boolean firstX11ActionOnProcess) { + public static void initSingleton() { if(!isInit) { synchronized(X11Util.class) { if(!isInit) { isInit = true; + if(DEBUG) { + System.out.println("X11UtilUtil.initSingleton()"); + } if(!NWJNILibLoader.loadNativeWindow("x11")) { throw new NativeWindowException("NativeWindow X11 native library load error."); } - final boolean callXInitThreads = XINITTHREADS_ALWAYS_ENABLED || firstX11ActionOnProcess; - final boolean isXInitThreadsOK = initialize0( XINITTHREADS_ALWAYS_ENABLED || firstX11ActionOnProcess, XERROR_STACKDUMP); + final boolean callXInitThreads = XINITTHREADS_ALWAYS_ENABLED ; + final boolean isXInitThreadsOK = initialize0( callXInitThreads, XERROR_STACKDUMP); isX11LockAvailable = isXInitThreadsOK && !HAS_XLOCKDISPLAY_BUG ; final long dpy = X11Lib.XOpenDisplay(null); @@ -124,8 +126,7 @@ public class X11Util { } if(DEBUG) { - System.err.println("X11Util firstX11ActionOnProcess: "+firstX11ActionOnProcess+ - ", requiresX11Lock "+requiresX11Lock+ + System.err.println("X11Util requiresX11Lock "+requiresX11Lock+ ", XInitThreads [called "+callXInitThreads+", OK "+isXInitThreadsOK+"]"+ ", isX11LockAvailable "+isX11LockAvailable+ ", X11 Display(NULL) <"+nullDisplayName+">"+ diff --git a/src/newt/classes/com/jogamp/newt/NewtFactory.java b/src/newt/classes/com/jogamp/newt/NewtFactory.java index 61dbfb34c..0644c9164 100644 --- a/src/newt/classes/com/jogamp/newt/NewtFactory.java +++ b/src/newt/classes/com/jogamp/newt/NewtFactory.java @@ -52,7 +52,7 @@ public class NewtFactory { // Work-around for initialization order problems on Mac OS X // between native Newt and (apparently) Fmod static { - NativeWindowFactory.initSingleton(false); // last resort .. + NativeWindowFactory.initSingleton(); // last resort .. WindowImpl.init(NativeWindowFactory.getNativeWindowType(true)); } diff --git a/src/newt/classes/com/jogamp/newt/util/MainThread.java b/src/newt/classes/com/jogamp/newt/util/MainThread.java index bbe415b2f..a6e2ae02b 100644 --- a/src/newt/classes/com/jogamp/newt/util/MainThread.java +++ b/src/newt/classes/com/jogamp/newt/util/MainThread.java @@ -101,7 +101,7 @@ public class MainThread { public static final boolean HINT_USE_MAIN_THREAD; static { - NativeWindowFactory.initSingleton(true); + NativeWindowFactory.initSingleton(); NEWTJNILibLoader.loadNEWT(); HINT_USE_MAIN_THREAD = !NativeWindowFactory.isAWTAvailable() || Debug.getBooleanProperty("newt.MainThread.force", true); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java index eb652584c..53995e8f7 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java @@ -47,7 +47,7 @@ public class TestRemoteWindow01NEWT extends UITestCase { @BeforeClass public static void initClass() { - NativeWindowFactory.initSingleton(true); + NativeWindowFactory.initSingleton(); width = 640; height = 480; } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java index a5b7a76e7..577119bcd 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java @@ -59,7 +59,7 @@ public class TestScreenMode00NEWT extends UITestCase { @BeforeClass public static void initClass() { - NativeWindowFactory.initSingleton(true); + NativeWindowFactory.initSingleton(); width = 640; height = 480; } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java index e9e66da2c..75a312686 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java @@ -57,7 +57,7 @@ public class TestScreenMode00bNEWT extends UITestCase { @BeforeClass public static void initClass() { - NativeWindowFactory.initSingleton(true); + NativeWindowFactory.initSingleton(); width = 640; height = 480; } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java index a99edfadb..bf72348f9 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java @@ -45,7 +45,7 @@ public class TestWindows01NEWT extends UITestCase { @BeforeClass public static void initClass() { - NativeWindowFactory.initSingleton(true); + NativeWindowFactory.initSingleton(); width = 256; height = 256; } -- cgit v1.2.3