28package com.jogamp.nativewindow.javafx;
30import java.lang.reflect.Method;
31import java.security.PrivilegedAction;
33import com.jogamp.nativewindow.AbstractGraphicsDevice;
34import com.jogamp.nativewindow.AbstractGraphicsScreen;
35import com.jogamp.nativewindow.NativeWindowException;
36import com.jogamp.nativewindow.NativeWindowFactory;
37import com.jogamp.nativewindow.VisualIDHolder;
38import com.jogamp.nativewindow.macosx.MacOSXGraphicsDevice;
39import com.jogamp.nativewindow.windows.WindowsGraphicsDevice;
40import com.jogamp.nativewindow.x11.X11GraphicsDevice;
41import com.jogamp.common.ExceptionUtils;
42import com.jogamp.common.util.InterruptedRuntimeException;
43import com.jogamp.common.util.ReflectionUtil;
44import com.jogamp.common.util.RunnableTask;
45import com.jogamp.common.util.SecurityUtil;
46import com.sun.javafx.tk.TKStage;
48import javafx.application.Platform;
49import javafx.stage.Window;
50import jogamp.nativewindow.Debug;
51import jogamp.nativewindow.x11.X11Lib;
52import jogamp.nativewindow.x11.X11Util;
55 private static final boolean DEBUG;
57 private static final boolean jfxAvailable;
58 private static final Method fxUserThreadGetter;
59 private static final Method tkStageGetter;
60 private static final Method glassWindowGetter;
61 private static final Method nativeWindowGetter;
63 private static final String nwt;
64 private static final boolean isOSX;
65 private static final boolean isIOS;
66 private static final boolean isWindows;
67 private static final boolean isX11;
70 final boolean[] _DEBUG =
new boolean[] {
true };
72 final Method[] res = SecurityUtil.doPrivileged(
new PrivilegedAction<Method[]>() {
74 public Method[] run() {
76 final Method[] res =
new Method[] {
null,
null,
null,
null };
79 _DEBUG[0] = Debug.debug(
"JFX");
83 final Class<?> jfxToolkitClz = ReflectionUtil.getClass(
"com.sun.javafx.tk.Toolkit",
false,
JFXAccessor.class.getClassLoader());
84 res[i] = jfxToolkitClz.getDeclaredMethod(
"getFxUserThread");
85 res[i++].setAccessible(
true);
97 final Class<?> jfxStageWindowClz = ReflectionUtil.getClass(
"javafx.stage.Window",
false,
JFXAccessor.class.getClassLoader());
99 final Class<?> jfxTkQuWindowStageClz = ReflectionUtil.getClass(
"com.sun.javafx.tk.quantum.WindowStage",
false,
JFXAccessor.class.getClassLoader());
100 final Class<?> jfxGlassUiWindowClz = ReflectionUtil.getClass(
"com.sun.glass.ui.Window",
false,
JFXAccessor.class.getClassLoader());
104 res[i] = jfxStageWindowClz.getDeclaredMethod(
"getPeer");
105 }
catch (
final NoSuchMethodException ex) {
107 res[i] = jfxStageWindowClz.getDeclaredMethod(
"impl_getPeer");
109 res[i++].setAccessible(
true);
111 res[i] = jfxTkQuWindowStageClz.getDeclaredMethod(
"getPlatformWindow");
112 res[i++].setAccessible(
true);
113 res[i] = jfxGlassUiWindowClz.getDeclaredMethod(
"getNativeWindow");
114 res[i++].setAccessible(
true);
115 }
catch (
final Throwable t) {
117 ExceptionUtils.dumpThrowable(
"jfx-init", t);
125 fxUserThreadGetter = res[i++];
126 tkStageGetter = res[i++];
127 glassWindowGetter = res[i++];
128 nativeWindowGetter = res[i++];
130 jfxAvailable =
null != fxUserThreadGetter &&
null != tkStageGetter &&
null != glassWindowGetter &&
null != nativeWindowGetter;
133 isOSX = NativeWindowFactory.TYPE_MACOSX == nwt;
134 isIOS = NativeWindowFactory.TYPE_IOS == nwt;
135 isWindows = NativeWindowFactory.TYPE_WINDOWS == nwt;
136 isX11 = NativeWindowFactory.TYPE_X11 == nwt;
140 System.err.println(Thread.currentThread().getName()+
" - Info: JFXAccessor.<init> available "+jfxAvailable+
", nwt "+nwt+
"( x11 "+isX11+
", win "+isWindows+
", osx "+isOSX+
")");
158 final Object rTaskLock =
new Object();
159 synchronized(rTaskLock) {
163 Platform.runLater(task);
165 final RunnableTask rTask =
new RunnableTask(task,
169 Platform.runLater(rTask);
171 while( rTask.isInQueue() ) {
174 }
catch (
final InterruptedException ie) {
175 throw new InterruptedRuntimeException(ie);
177 final Throwable throwable = rTask.getThrowable();
178 if(
null!=throwable) {
182 throw new RuntimeException(throwable);
190 return (Thread) fxUserThreadGetter.invoke(
null);
191 }
catch (
final Throwable e) {
197 return null != t ? t.getName() :
null;
204 return null == t || !t.isAlive();
211 return Thread.currentThread() == t;
218 return null == t || !t.isAlive() || Thread.currentThread() == t;
230 final String connection =
null;
231 final long x11DeviceHandle = X11Util.openDisplay(connection);
232 if( 0 == x11DeviceHandle ) {
243 throw new UnsupportedOperationException(
"n/a for this windowing system: "+nwt);
257 return X11Lib.GetVisualIDFromWindow(device.
getHandle(), windowHandle);
259 if( isWindows || isOSX ) {
262 throw new UnsupportedOperationException(
"n/a for this windowing system: "+nwt);
271 final long h[] = { 0 };
276 final TKStage tkStage = (TKStage) tkStageGetter.invoke(stageWindow);
277 if(
null != tkStage ) {
278 final Object platformWindow = glassWindowGetter.invoke(tkStage);
279 if(
null != platformWindow ) {
280 final Object nativeHandle = nativeWindowGetter.invoke(platformWindow);
281 h[0] = ((Long) nativeHandle).longValue();
283 System.err.println(Thread.currentThread().getName()+
" - Info: JFXAccessor null GlassWindow");
286 System.err.println(Thread.currentThread().getName()+
" - Info: JFXAccessor null TKStage");
288 }
catch (
final Throwable e) {
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
static synchronized void initSingleton()
Static one time initialization of this factory.
static String getNativeWindowType(final boolean useCustom)
static AbstractGraphicsScreen createScreen(final AbstractGraphicsDevice device, int screen)
static long getWindowHandle(final Window stageWindow)
static AbstractGraphicsScreen getScreen(final AbstractGraphicsDevice device, final int screen)
static String getJFXThreadName()
static boolean hasJFXThreadStopped()
static AbstractGraphicsDevice getDevice(final Window stageWindow)
static boolean isJFXThreadOrHasJFXThreadStopped()
static Thread getJFXThread()
static boolean isJFXAvailable()
static int getNativeVisualID(final AbstractGraphicsDevice device, final long windowHandle)
static boolean isJFXThread()
static void runOnJFXThread(final boolean wait, final Runnable task)
Runs given task on the JFX Thread if it has not stopped and if caller is not already on the JFX Threa...
Encapsulates a graphics device on MacOSX platforms.
Encapsulates a graphics device on Windows platforms.
Encapsulates a graphics device on X11 platforms.
A interface describing a graphics device in a toolkit-independent manner.
long getHandle()
Returns the native handle of the underlying native device, if such thing exist.
static int DEFAULT_UNIT
Default unit id for the 1st device: 0.
A interface describing a graphics screen in a toolkit-independent manner.
Visual ID holder interface.
static final int VID_UNDEFINED
getVisualID(VIDType) result indicating an undefined value, which could be cause by an unsupported que...