Top Fields Constructors Methods
jogamp.nativewindow.macosx

public Class OSXUtil

extends Object
implements ToolkitProperties
Class Inheritance
All Implemented Interfaces
jogamp.nativewindow.ToolkitProperties
Imports
com.jogamp.nativewindow.NativeWindowException, .NativeWindowFactory, com.jogamp.nativewindow.util.Insets, .Point, com.jogamp.common.util.Function, .FunctionTask, .InterruptedRuntimeException, .RunnableTask, jogamp.nativewindow.Debug, .NWJNILibLoader, .ToolkitProperties

Field Summary

Modifier and TypeField and Description
private static Runnable
private static final boolean
private static boolean
public static final int
MAX_PIXELSCALE

FIXME HiDPI: OSX unique and maximum value

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
AddCASublayer(final long rootCALayer, final long subCALayer, final int
x-coord of the sub-CALayer in window units (points)
x
,
final int
y-coord of the sub-CALayer in window units (points)
y
,
final int
width of the sub-CALayer in window units (points)
width
,
final int
height of the sub-CALayer in window units (points)
height
,
final float
scale for HiDPI support: pixel-dim = window-dim x scale
contentsScale
,
final int caLayerQuirks)

Attach a sub CALayer to the root CALayer

Method will trigger a display call to the CALayer hierarchy to enforce resource creation if required, e.g. an NSOpenGLContext.

private static native void
AddCASublayer0(long rootCALayer, long subCALayer, int x, int y, int width, int height, float contentsScale, int caLayerQuirks)

public static long

Returns:

the new CALayer object
CreateCALayer
(final int
width of the CALayer in window units (points)
width
,
final int
height of the CALayer in window units (points)
height
,
final float
scale for HiDPI support: pixel-dim = window-dim x scale
contentsScale
)

Create a CALayer suitable to act as a root CALayer.

private static native long
CreateCALayer0(int width, int height, float contentsScale)

public static long
CreateNSWindow(final int x, final int y, final int width, final int height)

private static native long
CreateNSWindow0(int x, int y, int width, int height)

public static void
DestroyCALayer(final long caLayer)

Destroy a CALayer.

private static native void
DestroyCALayer0(long caLayer)

public static void
DestroyNSWindow(final long nsWindow)

private static native void
DestroyNSWindow0(long nsWindow)

public static void
FixCALayerLayout(final long
the root surface layer, maybe null.
rootCALayer
,
final long
the client surface layer, maybe null.
subCALayer
,
final boolean
TODO
visible
,
final int x, final int y, final int
the expected width in window units (points)
width
,
final int
the expected height in window units (points)
height
,
final int
TODO
caLayerQuirks
)

Fix root and sub CALayer position to 0/0 and size

If the sub CALayer implements the Objective-C NativeWindow protocol NWDedicatedSize (e.g. JOGL's MyNSOpenGLLayer), the dedicated size is passed to the layer, which propagates it appropriately.

private static native void
FixCALayerLayout0(long rootCALayer, long subCALayer, boolean visible, int x, int y, int width, int height, int caLayerQuirks)

public static Insets
GetInsets(final long windowOrView)

private static native Object
GetInsets0(long windowOrView)

public static Point

Returns:

top-left client-area position in window units
GetLocationOnScreen
(final long windowOrView, final int src_x, final int src_y)

private static native Object
GetLocationOnScreen0(long windowOrView, int src_x, int src_y)

public static long
GetNSView(final long nsWindow)

private static native long
GetNSView0(long nsWindow)

public static long
GetNSWindow(final long nsView)

private static native long
GetNSWindow0(long nsView)

public static double
GetPixelScale(final long windowOrView)

private static native double
GetPixelScale1(int displayID)

private static native double
GetPixelScale2(long windowOrView)

public static double
GetPixelScaleByDisplayID(final int displayID)

public static int
GetScreenRefreshRate(final int scrn_idx)

Returns the screen refresh rate in Hz.

private static native int
GetScreenRefreshRate0(int scrn_idx)

public static final boolean
private static native boolean
initIDs0()

private static boolean isAWTEDTMainThreadInit = false; private static boolean isAWTEDTMainThread; public synchronized static boolean isAWTEDTMainThread() { if(!isAWTEDTMainThreadInit) { isAWTEDTMainThreadInit = true; if(Platform.AWT_AVAILABLE) { AWTEDTExecutor.singleton.invoke(true, new Runnable() { public void run() { isAWTEDTMainThread = IsMainThread(); System.err.println("XXX: "+Thread.currentThread().getName()+" - isAWTEDTMainThread "+isAWTEDTMainThread); } }); } else { isAWTEDTMainThread = false; } } return isAWTEDTMainThread; }

public static synchronized void
public static boolean
private static native boolean
public static boolean
isNSView(final long object)

private static native boolean
isNSView0(long object)

public static boolean
isNSWindow(final long object)

private static native boolean
isNSWindow0(long object)

public static void
KickNSApp()

Wakes up NSApp thread by sending an empty NSEvent ..

private static native void
public static void
RemoveCASublayer(final long rootCALayer, final long subCALayer)

Detach a sub CALayer from the root CALayer.

private static native void
RemoveCASublayer0(long rootCALayer, long subCALayer)

public static boolean
public static void
RunLater(final boolean
if true, run on main-thread, otherwise on the current OSX thread.
onMain
,
final Runnable runnable, final int
delay to run the runnable in milliseconds
delay
)

Run later on ..

private static native void
RunLater0(boolean onMain, boolean kickNSApp, Runnable runnable, int delay)

public static void
RunOnMainThread(final boolean waitUntilDone, final boolean
if true issues KickNSApp()
kickNSApp
,
final Runnable runnable)

Run on OSX UI main thread.

public static <R, A> R
RunOnMainThread(final boolean waitUntilDone, final boolean
if true issues KickNSApp()
kickNSApp
,
final Function<R, A> func, final A... args)

Run on OSX UI main thread.

private static native void
RunOnMainThread0(boolean kickNSApp, Runnable runnable)

public static void
SetCALayerPixelScale(final long
the root surface layer, maybe null.
rootCALayer
,
final long
the client surface layer, maybe null.
subCALayer
,
final float
scale for HiDPI support: pixel-dim = window-dim x scale
contentsScale
)

Set root and sub CALayer pixelScale / contentScale for HiDPI

private static native void
SetCALayerPixelScale0(long rootCALayer, long subCALayer, float contentsScale)

public static void
public static void
WaitUntilFinish()

Issues a RunOnMainThread(boolean, boolean, Runnable) w/ an NOP runnable, while waiting until done and issuing KickNSApp().

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_nopback to summary
private static Runnable _nop
DEBUGback to summary
private static final boolean DEBUG
isInitback to summary
private static boolean isInit
MAX_PIXELSCALEback to summary
public static final int MAX_PIXELSCALE

FIXME HiDPI: OSX unique and maximum value

Constructor Detail

OSXUtilback to summary
public OSXUtil()

Method Detail

AddCASublayerback to summary
public static void AddCASublayer(final long rootCALayer, final long subCALayer, final int x, final int y, final int width, final int height, final float contentsScale, final int caLayerQuirks)

Attach a sub CALayer to the root CALayer

Method will trigger a display call to the CALayer hierarchy to enforce resource creation if required, e.g. an NSOpenGLContext.

Hence it is important that related resources are not locked if they will be used for creation.

Parameters
x:int

x-coord of the sub-CALayer in window units (points)

y:int

y-coord of the sub-CALayer in window units (points)

width:int

width of the sub-CALayer in window units (points)

height:int

height of the sub-CALayer in window units (points)

contentsScale:float

scale for HiDPI support: pixel-dim = window-dim x scale

See Also
CreateCALayer(int, int, float), RemoveCASublayer(long, long, boolean)
AddCASublayer0back to summary
private static native void AddCASublayer0(long rootCALayer, long subCALayer, int x, int y, int width, int height, float contentsScale, int caLayerQuirks)
CreateCALayerback to summary
public static long CreateCALayer(final int width, final int height, final float contentsScale)

Create a CALayer suitable to act as a root CALayer.

Parameters
width:int

width of the CALayer in window units (points)

height:int

height of the CALayer in window units (points)

contentsScale:float

scale for HiDPI support: pixel-dim = window-dim x scale

Returns:long

the new CALayer object

See Also
DestroyCALayer(long), AddCASublayer(long, long)
CreateCALayer0back to summary
private static native long CreateCALayer0(int width, int height, float contentsScale)
CreateNSWindowback to summary
public static long CreateNSWindow(final int x, final int y, final int width, final int height)
CreateNSWindow0back to summary
private static native long CreateNSWindow0(int x, int y, int width, int height)
DestroyCALayerback to summary
public static void DestroyCALayer(final long caLayer)

Destroy a CALayer.

See Also
CreateCALayer(int, int, float)
DestroyCALayer0back to summary
private static native void DestroyCALayer0(long caLayer)
DestroyNSWindowback to summary
public static void DestroyNSWindow(final long nsWindow)
DestroyNSWindow0back to summary
private static native void DestroyNSWindow0(long nsWindow)
FixCALayerLayoutback to summary
public static void FixCALayerLayout(final long rootCALayer, final long subCALayer, final boolean visible, final int x, final int y, final int width, final int height, final int caLayerQuirks)

Fix root and sub CALayer position to 0/0 and size

If the sub CALayer implements the Objective-C NativeWindow protocol NWDedicatedSize (e.g. JOGL's MyNSOpenGLLayer), the dedicated size is passed to the layer, which propagates it appropriately.

On OSX/Java7 our root CALayer's frame position and size gets corrupted by its NSView, hence we have created the NWDedicatedSize protocol.

Parameters
rootCALayer:long

the root surface layer, maybe null.

subCALayer:long

the client surface layer, maybe null.

visible:boolean

TODO

width:int

the expected width in window units (points)

height:int

the expected height in window units (points)

caLayerQuirks:int

TODO

FixCALayerLayout0back to summary
private static native void FixCALayerLayout0(long rootCALayer, long subCALayer, boolean visible, int x, int y, int width, int height, int caLayerQuirks)
GetInsetsback to summary
public static Insets GetInsets(final long windowOrView)
GetInsets0back to summary
private static native Object GetInsets0(long windowOrView)
GetLocationOnScreenback to summary
public static Point GetLocationOnScreen(final long windowOrView, final int src_x, final int src_y)
Returns:Point

top-left client-area position in window units

GetLocationOnScreen0back to summary
private static native Object GetLocationOnScreen0(long windowOrView, int src_x, int src_y)
GetNSViewback to summary
public static long GetNSView(final long nsWindow)
GetNSView0back to summary
private static native long GetNSView0(long nsWindow)
GetNSWindowback to summary
public static long GetNSWindow(final long nsView)
GetNSWindow0back to summary
private static native long GetNSWindow0(long nsView)
GetPixelScaleback to summary
public static double GetPixelScale(final long windowOrView)
GetPixelScale1back to summary
private static native double GetPixelScale1(int displayID)
GetPixelScale2back to summary
private static native double GetPixelScale2(long windowOrView)
GetPixelScaleByDisplayIDback to summary
public static double GetPixelScaleByDisplayID(final int displayID)
GetScreenRefreshRateback to summary
public static int GetScreenRefreshRate(final int scrn_idx)

Returns the screen refresh rate in Hz. If unavailable, returns 60Hz.

GetScreenRefreshRate0back to summary
private static native int GetScreenRefreshRate0(int scrn_idx)
hasThreadingIssuesback to summary
public static final boolean hasThreadingIssues()

Called by NativeWindowFactory#initSingleton()

See Also
ToolkitProperties
initIDs0back to summary
private static native boolean initIDs0()

private static boolean isAWTEDTMainThreadInit = false; private static boolean isAWTEDTMainThread; public synchronized static boolean isAWTEDTMainThread() { if(!isAWTEDTMainThreadInit) { isAWTEDTMainThreadInit = true; if(Platform.AWT_AVAILABLE) { AWTEDTExecutor.singleton.invoke(true, new Runnable() { public void run() { isAWTEDTMainThread = IsMainThread(); System.err.println("XXX: "+Thread.currentThread().getName()+" - isAWTEDTMainThread "+isAWTEDTMainThread); } }); } else { isAWTEDTMainThread = false; } } return isAWTEDTMainThread; }

initSingletonback to summary
public static synchronized void initSingleton()

Called by NativeWindowFactory#initSingleton()

See Also
ToolkitProperties
IsMainThreadback to summary
public static boolean IsMainThread()
IsMainThread0back to summary
private static native boolean IsMainThread0()
isNSViewback to summary
public static boolean isNSView(final long object)
isNSView0back to summary
private static native boolean isNSView0(long object)
isNSWindowback to summary
public static boolean isNSWindow(final long object)
isNSWindow0back to summary
private static native boolean isNSWindow0(long object)
KickNSAppback to summary
public static void KickNSApp()

Wakes up NSApp thread by sending an empty NSEvent ..

This is deemed important sometimes where resources shall get freed ASAP, e.g. GL context etc.

The following scenarios requiring this wake-up are currently known:

  • Destruction of an OpenGL context
  • Destruction of Windows .. ?
  • Stopping the NSApp

FIXME: Complete list of scenarios and reason it.
KickNSApp0back to summary
private static native void KickNSApp0()
RemoveCASublayerback to summary
public static void RemoveCASublayer(final long rootCALayer, final long subCALayer)

Detach a sub CALayer from the root CALayer.

RemoveCASublayer0back to summary
private static native void RemoveCASublayer0(long rootCALayer, long subCALayer)
requiresToolkitLockback to summary
public static boolean requiresToolkitLock()

Called by NativeWindowFactory#initSingleton()

See Also
ToolkitProperties
RunLaterback to summary
public static void RunLater(final boolean onMain, final Runnable runnable, final int delay)

Run later on ..

Parameters
onMain:boolean

if true, run on main-thread, otherwise on the current OSX thread.

delay:int

delay to run the runnable in milliseconds

RunLater0back to summary
private static native void RunLater0(boolean onMain, boolean kickNSApp, Runnable runnable, int delay)
RunOnMainThreadback to summary
public static void RunOnMainThread(final boolean waitUntilDone, final boolean kickNSApp, final Runnable runnable)

Run on OSX UI main thread.

'waitUntilDone' is implemented on Java site via lock/wait on RunnableTask to not freeze OSX main thread.

Parameters
kickNSApp:boolean

if true issues KickNSApp()

RunOnMainThreadback to summary
public static <R, A> R RunOnMainThread(final boolean waitUntilDone, final boolean kickNSApp, final Function<R, A> func, final A... args)

Run on OSX UI main thread.

'waitUntilDone' is implemented on Java site via lock/wait on FunctionTask to not freeze OSX main thread.

Parameters
kickNSApp:boolean

if true issues KickNSApp()

RunOnMainThread0back to summary
private static native void RunOnMainThread0(boolean kickNSApp, Runnable runnable)
SetCALayerPixelScaleback to summary
public static void SetCALayerPixelScale(final long rootCALayer, final long subCALayer, final float contentsScale)

Set root and sub CALayer pixelScale / contentScale for HiDPI

Parameters
rootCALayer:long

the root surface layer, maybe null.

subCALayer:long

the client surface layer, maybe null.

contentsScale:float

scale for HiDPI support: pixel-dim = window-dim x scale

SetCALayerPixelScale0back to summary
private static native void SetCALayerPixelScale0(long rootCALayer, long subCALayer, float contentsScale)
shutdownback to summary
public static void shutdown()

Called by NativeWindowFactory#shutdown()

See Also
ToolkitProperties
WaitUntilFinishback to summary
public static void WaitUntilFinish()

Issues a RunOnMainThread(boolean, boolean, Runnable) w/ an NOP runnable, while waiting until done and issuing KickNSApp().