mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-01 15:58:25 +00:00
* EventInfo.cs:
* AglContext.cs: * MacOSKeyMap.cs: * CarbonInput.cs: * Application.cs: * MacOSFactory.cs: * CarbonGLNative.cs: * CarbonWindowInfo.cs: * MacOSGraphicsMode.cs: * QuartzDisplayDeviceDriver.cs: Normalized code formatting.
This commit is contained in:
parent
b30ec15167
commit
64210383de
|
@ -32,8 +32,8 @@ namespace OpenTK.Platform.MacOS
|
||||||
GraphicsMode graphics_mode;
|
GraphicsMode graphics_mode;
|
||||||
CarbonWindowInfo carbonWindow;
|
CarbonWindowInfo carbonWindow;
|
||||||
IntPtr shareContextRef;
|
IntPtr shareContextRef;
|
||||||
DisplayDevice device;
|
DisplayDevice device;
|
||||||
bool mIsFullscreen = false;
|
bool mIsFullscreen = false;
|
||||||
|
|
||||||
public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
|
public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
|
||||||
{
|
{
|
||||||
|
@ -45,18 +45,17 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
if (shareContext is AglContext)
|
if (shareContext is AglContext)
|
||||||
shareContextRef = ((AglContext)shareContext).Handle.Handle;
|
shareContextRef = ((AglContext)shareContext).Handle.Handle;
|
||||||
if (shareContext is GraphicsContext)
|
if (shareContext is GraphicsContext)
|
||||||
{
|
{
|
||||||
ContextHandle shareHandle = shareContext != null ?
|
ContextHandle shareHandle = shareContext != null ? (shareContext as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;
|
||||||
(shareContext as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;
|
|
||||||
|
|
||||||
shareContextRef = shareHandle.Handle;
|
shareContextRef = shareHandle.Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shareContextRef == IntPtr.Zero)
|
if (shareContextRef == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
Debug.Print("No context sharing will take place.");
|
Debug.Print("No context sharing will take place.");
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateContext(mode, carbonWindow, shareContextRef, true);
|
CreateContext(mode, carbonWindow, shareContextRef, true);
|
||||||
}
|
}
|
||||||
|
@ -86,10 +85,9 @@ namespace OpenTK.Platform.MacOS
|
||||||
aglAttributes.Add((int)pixelFormatAttribute);
|
aglAttributes.Add((int)pixelFormatAttribute);
|
||||||
aglAttributes.Add(value);
|
aglAttributes.Add(value);
|
||||||
}
|
}
|
||||||
void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow,
|
void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen)
|
||||||
IntPtr shareContextRef, bool fullscreen)
|
|
||||||
{
|
{
|
||||||
List<int> aglAttributes = new List<int>();
|
List<int> aglAttributes = new List<int>();
|
||||||
|
|
||||||
Debug.Print("AGL pixel format attributes:");
|
Debug.Print("AGL pixel format attributes:");
|
||||||
Debug.Indent();
|
Debug.Indent();
|
||||||
|
@ -139,21 +137,18 @@ namespace OpenTK.Platform.MacOS
|
||||||
// Choose a pixel format with the attributes we specified.
|
// Choose a pixel format with the attributes we specified.
|
||||||
if (fullscreen)
|
if (fullscreen)
|
||||||
{
|
{
|
||||||
IntPtr gdevice;
|
IntPtr gdevice;
|
||||||
IntPtr cgdevice = GetQuartzDevice(carbonWindow);
|
IntPtr cgdevice = GetQuartzDevice(carbonWindow);
|
||||||
|
|
||||||
if (cgdevice == IntPtr.Zero)
|
if (cgdevice == IntPtr.Zero)
|
||||||
cgdevice = QuartzDisplayDeviceDriver.MainDisplay;
|
cgdevice = QuartzDisplayDeviceDriver.MainDisplay;
|
||||||
|
|
||||||
OSStatus status = Carbon.API.DMGetGDeviceByDisplayID(
|
OSStatus status = Carbon.API.DMGetGDeviceByDisplayID(cgdevice, out gdevice, false);
|
||||||
cgdevice, out gdevice, false);
|
|
||||||
|
|
||||||
if (status != OSStatus.NoError)
|
if (status != OSStatus.NoError)
|
||||||
throw new MacOSException(status, "DMGetGDeviceByDisplayID failed.");
|
throw new MacOSException(status, "DMGetGDeviceByDisplayID failed.");
|
||||||
|
|
||||||
myAGLPixelFormat = Agl.aglChoosePixelFormat(
|
myAGLPixelFormat = Agl.aglChoosePixelFormat(ref gdevice, 1, aglAttributes.ToArray());
|
||||||
ref gdevice, 1,
|
|
||||||
aglAttributes.ToArray());
|
|
||||||
|
|
||||||
Agl.AglError err = Agl.GetError();
|
Agl.AglError err = Agl.GetError();
|
||||||
|
|
||||||
|
@ -166,20 +161,19 @@ namespace OpenTK.Platform.MacOS
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
myAGLPixelFormat = Agl.aglChoosePixelFormat(
|
myAGLPixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, aglAttributes.ToArray());
|
||||||
IntPtr.Zero, 0,
|
|
||||||
aglAttributes.ToArray());
|
|
||||||
|
|
||||||
MyAGLReportError("aglChoosePixelFormat");
|
MyAGLReportError("aglChoosePixelFormat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Debug.Print("Creating AGL context. Sharing with {0}", shareContextRef);
|
Debug.Print("Creating AGL context. Sharing with {0}", shareContextRef);
|
||||||
|
|
||||||
// create the context and share it with the share reference.
|
// create the context and share it with the share reference.
|
||||||
Handle = new ContextHandle( Agl.aglCreateContext(myAGLPixelFormat, shareContextRef));
|
Handle = new ContextHandle(Agl.aglCreateContext(myAGLPixelFormat, shareContextRef));
|
||||||
MyAGLReportError("aglCreateContext");
|
MyAGLReportError("aglCreateContext");
|
||||||
|
|
||||||
// Free the pixel format from memory.
|
// Free the pixel format from memory.
|
||||||
|
@ -197,25 +191,25 @@ namespace OpenTK.Platform.MacOS
|
||||||
Debug.Print("context: {0}", Handle.Handle);
|
Debug.Print("context: {0}", Handle.Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IntPtr GetQuartzDevice(CarbonWindowInfo carbonWindow)
|
private IntPtr GetQuartzDevice(CarbonWindowInfo carbonWindow)
|
||||||
{
|
{
|
||||||
IntPtr windowRef = carbonWindow.WindowRef;
|
IntPtr windowRef = carbonWindow.WindowRef;
|
||||||
|
|
||||||
if (CarbonGLNative.WindowRefMap.ContainsKey(windowRef) == false)
|
if (CarbonGLNative.WindowRefMap.ContainsKey(windowRef) == false)
|
||||||
return IntPtr.Zero;
|
return IntPtr.Zero;
|
||||||
|
|
||||||
WeakReference nativeRef = CarbonGLNative.WindowRefMap[windowRef];
|
WeakReference nativeRef = CarbonGLNative.WindowRefMap[windowRef];
|
||||||
if (nativeRef.IsAlive == false)
|
if (nativeRef.IsAlive == false)
|
||||||
return IntPtr.Zero;
|
return IntPtr.Zero;
|
||||||
|
|
||||||
CarbonGLNative window = nativeRef.Target as CarbonGLNative;
|
CarbonGLNative window = nativeRef.Target as CarbonGLNative;
|
||||||
|
|
||||||
if (window == null)
|
if (window == null)
|
||||||
return IntPtr.Zero;
|
return IntPtr.Zero;
|
||||||
|
|
||||||
return QuartzDisplayDeviceDriver.HandleTo(window.TargetDisplayDevice);
|
return QuartzDisplayDeviceDriver.HandleTo(window.TargetDisplayDevice);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetBufferRect(CarbonWindowInfo carbonWindow)
|
void SetBufferRect(CarbonWindowInfo carbonWindow)
|
||||||
{
|
{
|
||||||
|
@ -228,10 +222,9 @@ namespace OpenTK.Platform.MacOS
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Rect rect = API.GetControlBounds(carbonWindow.WindowRef);
|
Rect rect = API.GetControlBounds(carbonWindow.WindowRef);
|
||||||
System.Windows.Forms.Form frm = (System.Windows.Forms.Form) ctrl.TopLevelControl;
|
System.Windows.Forms.Form frm = (System.Windows.Forms.Form)ctrl.TopLevelControl;
|
||||||
|
|
||||||
System.Drawing.Point loc =
|
System.Drawing.Point loc = frm.PointToClient(ctrl.PointToScreen(System.Drawing.Point.Empty));
|
||||||
frm.PointToClient(ctrl.PointToScreen(System.Drawing.Point.Empty));
|
|
||||||
|
|
||||||
rect.X = (short)loc.X;
|
rect.X = (short)loc.X;
|
||||||
rect.Y = (short)loc.Y;
|
rect.Y = (short)loc.Y;
|
||||||
|
@ -259,7 +252,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
void SetDrawable(CarbonWindowInfo carbonWindow)
|
void SetDrawable(CarbonWindowInfo carbonWindow)
|
||||||
{
|
{
|
||||||
IntPtr windowPort = GetWindowPortForWindowInfo(carbonWindow);
|
IntPtr windowPort = GetWindowPortForWindowInfo(carbonWindow);
|
||||||
//Debug.Print("Setting drawable for context {0} to window port: {1}", Handle.Handle, windowPort);
|
//Debug.Print("Setting drawable for context {0} to window port: {1}", Handle.Handle, windowPort);
|
||||||
|
|
||||||
Agl.aglSetDrawable(Handle.Handle, windowPort);
|
Agl.aglSetDrawable(Handle.Handle, windowPort);
|
||||||
|
|
||||||
|
@ -276,6 +269,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
windowPort = API.GetWindowPort(controlOwner);
|
windowPort = API.GetWindowPort(controlOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
windowPort = API.GetWindowPort(carbonWindow.WindowRef);
|
windowPort = API.GetWindowPort(carbonWindow.WindowRef);
|
||||||
|
|
||||||
|
@ -285,32 +279,33 @@ namespace OpenTK.Platform.MacOS
|
||||||
{
|
{
|
||||||
CarbonWindowInfo carbonWindow = (CarbonWindowInfo)window;
|
CarbonWindowInfo carbonWindow = (CarbonWindowInfo)window;
|
||||||
|
|
||||||
if (carbonWindow.GoFullScreenHack)
|
if (carbonWindow.GoFullScreenHack)
|
||||||
{
|
{
|
||||||
carbonWindow.GoFullScreenHack = false;
|
carbonWindow.GoFullScreenHack = false;
|
||||||
CarbonGLNative wind = GetCarbonWindow(carbonWindow);
|
CarbonGLNative wind = GetCarbonWindow(carbonWindow);
|
||||||
|
|
||||||
if (wind != null)
|
if (wind != null)
|
||||||
wind.SetFullscreen(this);
|
wind.SetFullscreen(this);
|
||||||
else
|
else
|
||||||
Debug.Print("Could not find window!");
|
Debug.Print("Could not find window!");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (carbonWindow.GoWindowedHack)
|
|
||||||
{
|
|
||||||
carbonWindow.GoWindowedHack = false;
|
|
||||||
CarbonGLNative wind = GetCarbonWindow(carbonWindow);
|
|
||||||
|
|
||||||
if (wind != null)
|
else if (carbonWindow.GoWindowedHack)
|
||||||
wind.UnsetFullscreen(this);
|
{
|
||||||
else
|
carbonWindow.GoWindowedHack = false;
|
||||||
Debug.Print("Could not find window!");
|
CarbonGLNative wind = GetCarbonWindow(carbonWindow);
|
||||||
|
|
||||||
}
|
if (wind != null)
|
||||||
|
wind.UnsetFullscreen(this);
|
||||||
|
else
|
||||||
|
Debug.Print("Could not find window!");
|
||||||
|
|
||||||
if (mIsFullscreen)
|
}
|
||||||
return;
|
|
||||||
|
if (mIsFullscreen)
|
||||||
|
return;
|
||||||
|
|
||||||
SetDrawable(carbonWindow);
|
SetDrawable(carbonWindow);
|
||||||
SetBufferRect(carbonWindow);
|
SetBufferRect(carbonWindow);
|
||||||
|
@ -318,67 +313,65 @@ namespace OpenTK.Platform.MacOS
|
||||||
Agl.aglUpdateContext(Handle.Handle);
|
Agl.aglUpdateContext(Handle.Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CarbonGLNative GetCarbonWindow(CarbonWindowInfo carbonWindow)
|
private CarbonGLNative GetCarbonWindow(CarbonWindowInfo carbonWindow)
|
||||||
{
|
{
|
||||||
WeakReference r = CarbonGLNative.WindowRefMap[carbonWindow.WindowRef];
|
WeakReference r = CarbonGLNative.WindowRefMap[carbonWindow.WindowRef];
|
||||||
|
|
||||||
if (r.IsAlive)
|
if (r.IsAlive)
|
||||||
{
|
{
|
||||||
return (CarbonGLNative) r.Target;
|
return (CarbonGLNative)r.Target;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return null;
|
else
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
void MyAGLReportError(string function)
|
void MyAGLReportError(string function)
|
||||||
{
|
{
|
||||||
Agl.AglError err = Agl.GetError();
|
Agl.AglError err = Agl.GetError();
|
||||||
|
|
||||||
if (err != Agl.AglError.NoError)
|
if (err != Agl.AglError.NoError)
|
||||||
throw new MacOSException((OSStatus)err, string.Format(
|
throw new MacOSException((OSStatus)err, string.Format("AGL Error from function {0}: {1} {2}", function, err, Agl.ErrorString(err)));
|
||||||
"AGL Error from function {0}: {1} {2}",
|
|
||||||
function, err, Agl.ErrorString(err)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool firstFullScreen = false;
|
bool firstFullScreen = false;
|
||||||
|
|
||||||
internal void SetFullScreen(CarbonWindowInfo info, out int width, out int height)
|
internal void SetFullScreen(CarbonWindowInfo info, out int width, out int height)
|
||||||
{
|
{
|
||||||
CarbonGLNative wind = GetCarbonWindow(info);
|
CarbonGLNative wind = GetCarbonWindow(info);
|
||||||
|
|
||||||
Debug.Print("Switching to full screen {0}x{1} on context {2}",
|
Debug.Print("Switching to full screen {0}x{1} on context {2}", wind.TargetDisplayDevice.Width, wind.TargetDisplayDevice.Height, Handle.Handle);
|
||||||
wind.TargetDisplayDevice.Width, wind.TargetDisplayDevice.Height, Handle.Handle);
|
|
||||||
|
|
||||||
CG.DisplayCapture(GetQuartzDevice(info));
|
CG.DisplayCapture(GetQuartzDevice(info));
|
||||||
Agl.aglSetFullScreen(Handle.Handle, wind.TargetDisplayDevice.Width, wind.TargetDisplayDevice.Height, 0, 0);
|
Agl.aglSetFullScreen(Handle.Handle, wind.TargetDisplayDevice.Width, wind.TargetDisplayDevice.Height, 0, 0);
|
||||||
MakeCurrent(info);
|
MakeCurrent(info);
|
||||||
|
|
||||||
width = wind.TargetDisplayDevice.Width;
|
width = wind.TargetDisplayDevice.Width;
|
||||||
height = wind.TargetDisplayDevice.Height;
|
height = wind.TargetDisplayDevice.Height;
|
||||||
|
|
||||||
// This is a weird hack to workaround a bug where the first time a context
|
// This is a weird hack to workaround a bug where the first time a context
|
||||||
// is made fullscreen, we just end up with a blank screen. So we undo it as fullscreen
|
// is made fullscreen, we just end up with a blank screen. So we undo it as fullscreen
|
||||||
// and redo it as fullscreen.
|
// and redo it as fullscreen.
|
||||||
if (firstFullScreen == false)
|
if (firstFullScreen == false)
|
||||||
{
|
{
|
||||||
firstFullScreen = true;
|
firstFullScreen = true;
|
||||||
UnsetFullScreen(info);
|
UnsetFullScreen(info);
|
||||||
SetFullScreen(info, out width, out height);
|
SetFullScreen(info, out width, out height);
|
||||||
}
|
}
|
||||||
|
|
||||||
mIsFullscreen = true;
|
mIsFullscreen = true;
|
||||||
}
|
}
|
||||||
internal void UnsetFullScreen(CarbonWindowInfo windowInfo)
|
internal void UnsetFullScreen(CarbonWindowInfo windowInfo)
|
||||||
{
|
{
|
||||||
Debug.Print("Unsetting AGL fullscreen.");
|
Debug.Print("Unsetting AGL fullscreen.");
|
||||||
Agl.aglSetDrawable(Handle.Handle, IntPtr.Zero);
|
Agl.aglSetDrawable(Handle.Handle, IntPtr.Zero);
|
||||||
Agl.aglUpdateContext(Handle.Handle);
|
Agl.aglUpdateContext(Handle.Handle);
|
||||||
|
|
||||||
CG.DisplayRelease(GetQuartzDevice(windowInfo));
|
CG.DisplayRelease(GetQuartzDevice(windowInfo));
|
||||||
Debug.Print("Resetting drawable.");
|
Debug.Print("Resetting drawable.");
|
||||||
SetDrawable(windowInfo);
|
SetDrawable(windowInfo);
|
||||||
|
|
||||||
mIsFullscreen = false;
|
mIsFullscreen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -409,18 +402,12 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
public override bool IsCurrent
|
public override bool IsCurrent
|
||||||
{
|
{
|
||||||
get
|
get { return (Handle.Handle == Agl.aglGetCurrentContext()); }
|
||||||
{
|
|
||||||
return (Handle.Handle == Agl.aglGetCurrentContext());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool VSync
|
public override bool VSync
|
||||||
{
|
{
|
||||||
get
|
get { return mVSync; }
|
||||||
{
|
|
||||||
return mVSync;
|
|
||||||
}
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
int intVal = value ? 1 : 0;
|
int intVal = value ? 1 : 0;
|
||||||
|
@ -453,18 +440,18 @@ namespace OpenTK.Platform.MacOS
|
||||||
Debug.Print("Disposing of AGL context.");
|
Debug.Print("Disposing of AGL context.");
|
||||||
Agl.aglSetCurrentContext(IntPtr.Zero);
|
Agl.aglSetCurrentContext(IntPtr.Zero);
|
||||||
|
|
||||||
//Debug.Print("Setting drawable to null for context {0}.", Handle.Handle);
|
//Debug.Print("Setting drawable to null for context {0}.", Handle.Handle);
|
||||||
//Agl.aglSetDrawable(Handle.Handle, IntPtr.Zero);
|
//Agl.aglSetDrawable(Handle.Handle, IntPtr.Zero);
|
||||||
|
|
||||||
// I do not know MacOS allows us to destroy a context from a separate thread,
|
// I do not know MacOS allows us to destroy a context from a separate thread,
|
||||||
// like the finalizer thread. It's untested, but worst case is probably
|
// like the finalizer thread. It's untested, but worst case is probably
|
||||||
// an exception on application exit, which would be logged to the console.
|
// an exception on application exit, which would be logged to the console.
|
||||||
Debug.Print("Destroying context");
|
Debug.Print("Destroying context");
|
||||||
if (Agl.aglDestroyContext(Handle.Handle) == true)
|
if (Agl.aglDestroyContext(Handle.Handle) == true)
|
||||||
{
|
{
|
||||||
Debug.Print("Context destruction completed successfully.");
|
Debug.Print("Context destruction completed successfully.");
|
||||||
Handle = ContextHandle.Zero;
|
Handle = ContextHandle.Zero;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// failed to destroy context.
|
// failed to destroy context.
|
||||||
|
@ -484,7 +471,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
#region IGraphicsContextInternal Members
|
#region IGraphicsContextInternal Members
|
||||||
|
|
||||||
private const string Library = "libdl.dylib";
|
private const string Library = "libdl.dylib";
|
||||||
|
|
||||||
[DllImport(Library, EntryPoint = "NSIsSymbolNameDefined")]
|
[DllImport(Library, EntryPoint = "NSIsSymbolNameDefined")]
|
||||||
private static extern bool NSIsSymbolNameDefined(string s);
|
private static extern bool NSIsSymbolNameDefined(string s);
|
||||||
|
|
|
@ -27,9 +27,10 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void Initialize()
|
static internal void Initialize()
|
||||||
{
|
{
|
||||||
if (mInitialized) return;
|
if (mInitialized)
|
||||||
|
return;
|
||||||
|
|
||||||
API.AcquireRootMenu();
|
API.AcquireRootMenu();
|
||||||
|
|
||||||
|
@ -41,21 +42,21 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
|
|
||||||
Debug.Print("Running on Mac OS X {0}.{1}.{2}.", osMajor, osMinor, osBugfix);
|
Debug.Print("Running on Mac OS X {0}.{1}.{2}.", osMajor, osMinor, osBugfix);
|
||||||
|
|
||||||
TransformProcessToForeground();
|
TransformProcessToForeground();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TransformProcessToForeground()
|
private static void TransformProcessToForeground()
|
||||||
{
|
{
|
||||||
Carbon.ProcessSerialNumber psn = new ProcessSerialNumber();
|
Carbon.ProcessSerialNumber psn = new ProcessSerialNumber();
|
||||||
|
|
||||||
Debug.Print("Setting process to be foreground application.");
|
Debug.Print("Setting process to be foreground application.");
|
||||||
|
|
||||||
API.GetCurrentProcess(ref psn);
|
API.GetCurrentProcess(ref psn);
|
||||||
API.TransformProcessType(ref psn, ProcessApplicationTransformState.kProcessTransformToForegroundApplication);
|
API.TransformProcessType(ref psn, ProcessApplicationTransformState.kProcessTransformToForegroundApplication);
|
||||||
API.SetFrontProcess(ref psn);
|
API.SetFrontProcess(ref psn);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static CarbonGLNative WindowEventHandler
|
static internal CarbonGLNative WindowEventHandler
|
||||||
{
|
{
|
||||||
get { return eventHandler; }
|
get { return eventHandler; }
|
||||||
set { eventHandler = value; }
|
set { eventHandler = value; }
|
||||||
|
@ -63,33 +64,16 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
|
|
||||||
static void ConnectEvents()
|
static void ConnectEvents()
|
||||||
{
|
{
|
||||||
EventTypeSpec[] eventTypes = new EventTypeSpec[]
|
|
||||||
{
|
|
||||||
new EventTypeSpec(EventClass.Application, AppEventKind.AppActivated),
|
|
||||||
new EventTypeSpec(EventClass.Application, AppEventKind.AppDeactivated),
|
|
||||||
new EventTypeSpec(EventClass.Application, AppEventKind.AppQuit),
|
|
||||||
|
|
||||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseDown),
|
EventTypeSpec[] eventTypes = new EventTypeSpec[] { new EventTypeSpec(EventClass.Application, AppEventKind.AppActivated), new EventTypeSpec(EventClass.Application, AppEventKind.AppDeactivated), new EventTypeSpec(EventClass.Application, AppEventKind.AppQuit), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseDown), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseUp), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseMoved), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseDragged), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseEntered), new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseExited), new EventTypeSpec(EventClass.Mouse, MouseEventKind.WheelMoved),
|
||||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseUp),
|
|
||||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseMoved),
|
|
||||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseDragged),
|
|
||||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseEntered),
|
|
||||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseExited),
|
|
||||||
new EventTypeSpec(EventClass.Mouse, MouseEventKind.WheelMoved),
|
|
||||||
|
|
||||||
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyDown),
|
|
||||||
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyRepeat),
|
|
||||||
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyUp),
|
|
||||||
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyModifiersChanged),
|
|
||||||
|
|
||||||
new EventTypeSpec(EventClass.AppleEvent, AppleEventKind.AppleEvent),
|
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyDown), new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyRepeat), new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyUp), new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyModifiersChanged), new EventTypeSpec(EventClass.AppleEvent, AppleEventKind.AppleEvent) };
|
||||||
};
|
|
||||||
|
|
||||||
MacOSEventHandler handler = EventHandler;
|
MacOSEventHandler handler = EventHandler;
|
||||||
uppHandler = API.NewEventHandlerUPP(handler);
|
uppHandler = API.NewEventHandlerUPP(handler);
|
||||||
|
|
||||||
API.InstallApplicationEventHandler(
|
API.InstallApplicationEventHandler(uppHandler, eventTypes, IntPtr.Zero, IntPtr.Zero);
|
||||||
uppHandler, eventTypes, IntPtr.Zero, IntPtr.Zero);
|
|
||||||
|
|
||||||
mInitialized = true;
|
mInitialized = true;
|
||||||
}
|
}
|
||||||
|
@ -100,26 +84,28 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
|
|
||||||
switch (evt.EventClass)
|
switch (evt.EventClass)
|
||||||
{
|
{
|
||||||
case EventClass.Application:
|
case EventClass.Application:
|
||||||
switch (evt.AppEventKind)
|
switch (evt.AppEventKind)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
return OSStatus.EventNotHandled;
|
return OSStatus.EventNotHandled;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EventClass.AppleEvent:
|
|
||||||
// only event here is the apple event.
|
|
||||||
Debug.Print("Processing apple event.");
|
|
||||||
API.ProcessAppleEvent(inEvent);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EventClass.Keyboard:
|
case EventClass.AppleEvent:
|
||||||
case EventClass.Mouse:
|
// only event here is the apple event.
|
||||||
if (WindowEventHandler != null)
|
Debug.Print("Processing apple event.");
|
||||||
{
|
API.ProcessAppleEvent(inEvent);
|
||||||
return WindowEventHandler.DispatchEvent(inCaller, inEvent, evt, userData);
|
break;
|
||||||
}
|
|
||||||
break;
|
case EventClass.Keyboard:
|
||||||
|
case EventClass.Mouse:
|
||||||
|
if (WindowEventHandler != null)
|
||||||
|
{
|
||||||
|
return WindowEventHandler.DispatchEvent(inCaller, inEvent, evt, userData);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OSStatus.EventNotHandled;
|
return OSStatus.EventNotHandled;
|
||||||
|
@ -142,7 +128,7 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static void ProcessEvents()
|
static internal void ProcessEvents()
|
||||||
{
|
{
|
||||||
API.ProcessEvents();
|
API.ProcessEvents();
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -65,17 +65,26 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
public IMouseDriver2 MouseDriver
|
public IMouseDriver2 MouseDriver
|
||||||
{
|
{
|
||||||
get { throw new NotImplementedException(); }
|
get
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IKeyboardDriver2 KeyboardDriver
|
public IKeyboardDriver2 KeyboardDriver
|
||||||
{
|
{
|
||||||
get { throw new NotImplementedException(); }
|
get
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGamePadDriver GamePadDriver
|
public IGamePadDriver GamePadDriver
|
||||||
{
|
{
|
||||||
get { throw new NotImplementedException(); }
|
get
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,8 @@ namespace OpenTK.Platform.MacOS
|
||||||
bool ownHandle = false;
|
bool ownHandle = false;
|
||||||
bool disposed = false;
|
bool disposed = false;
|
||||||
bool isControl = false;
|
bool isControl = false;
|
||||||
bool goFullScreenHack = false;
|
bool goFullScreenHack = false;
|
||||||
bool goWindowedHack = false;
|
bool goWindowedHack = false;
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
|
@ -72,16 +72,16 @@ namespace OpenTK.Platform.MacOS
|
||||||
get { return this.windowRef; }
|
get { return this.windowRef; }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool GoFullScreenHack
|
internal bool GoFullScreenHack
|
||||||
{
|
{
|
||||||
get { return goFullScreenHack; }
|
get { return goFullScreenHack; }
|
||||||
set { goFullScreenHack = value; }
|
set { goFullScreenHack = value; }
|
||||||
}
|
}
|
||||||
internal bool GoWindowedHack
|
internal bool GoWindowedHack
|
||||||
{
|
{
|
||||||
get { return goWindowedHack; }
|
get { return goWindowedHack; }
|
||||||
set { goWindowedHack = value; }
|
set { goWindowedHack = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -96,8 +96,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
/// <returns>A System.String that represents the current window.</returns>
|
/// <returns>A System.String that represents the current window.</returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return String.Format("MacOS.CarbonWindowInfo: Handle {0}",
|
return String.Format("MacOS.CarbonWindowInfo: Handle {0}", this.WindowRef);
|
||||||
this.WindowRef);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -25,14 +25,17 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
uint _eventKind;
|
uint _eventKind;
|
||||||
EventClass _eventClass;
|
EventClass _eventClass;
|
||||||
|
|
||||||
public EventClass EventClass { get { return _eventClass; }}
|
public EventClass EventClass
|
||||||
|
{
|
||||||
|
get { return _eventClass; }
|
||||||
|
}
|
||||||
|
|
||||||
public WindowEventKind WindowEventKind
|
public WindowEventKind WindowEventKind
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (EventClass == EventClass.Window)
|
if (EventClass == EventClass.Window)
|
||||||
return (WindowEventKind) _eventKind;
|
return (WindowEventKind)_eventKind;
|
||||||
else
|
else
|
||||||
throw new InvalidCastException("Event is not a Window event.");
|
throw new InvalidCastException("Event is not a Window event.");
|
||||||
}
|
}
|
||||||
|
@ -42,7 +45,7 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (EventClass == EventClass.Keyboard)
|
if (EventClass == EventClass.Keyboard)
|
||||||
return (KeyboardEventKind) _eventKind;
|
return (KeyboardEventKind)_eventKind;
|
||||||
else
|
else
|
||||||
throw new InvalidCastException("Event is not a Keyboard event.");
|
throw new InvalidCastException("Event is not a Keyboard event.");
|
||||||
}
|
}
|
||||||
|
@ -52,7 +55,7 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (EventClass == EventClass.Mouse)
|
if (EventClass == EventClass.Mouse)
|
||||||
return (MouseEventKind) _eventKind;
|
return (MouseEventKind)_eventKind;
|
||||||
else
|
else
|
||||||
throw new InvalidCastException("Event is not an Mouse event.");
|
throw new InvalidCastException("Event is not an Mouse event.");
|
||||||
}
|
}
|
||||||
|
@ -62,7 +65,7 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (EventClass == EventClass.Application)
|
if (EventClass == EventClass.Application)
|
||||||
return (AppEventKind) _eventKind;
|
return (AppEventKind)_eventKind;
|
||||||
else
|
else
|
||||||
throw new InvalidCastException("Event is not an Application event.");
|
throw new InvalidCastException("Event is not an Application event.");
|
||||||
}
|
}
|
||||||
|
@ -71,16 +74,16 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
switch(EventClass)
|
switch (EventClass)
|
||||||
{
|
{
|
||||||
case EventClass.Application:
|
case EventClass.Application:
|
||||||
return "Event: App " + AppEventKind.ToString();
|
return "Event: App " + AppEventKind.ToString();
|
||||||
case EventClass.Keyboard:
|
case EventClass.Keyboard:
|
||||||
return "Event: Keyboard " + KeyboardEventKind.ToString();
|
return "Event: Keyboard " + KeyboardEventKind.ToString();
|
||||||
case EventClass.Mouse:
|
case EventClass.Mouse:
|
||||||
return "Event: Mouse " + MouseEventKind.ToString();
|
return "Event: Mouse " + MouseEventKind.ToString();
|
||||||
case EventClass.Window:
|
case EventClass.Window:
|
||||||
return "Event: Window " + WindowEventKind.ToString();
|
return "Event: Window " + WindowEventKind.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Event: Unknown Class " + EventClass.ToString() + " kind: " + _eventKind.ToString();
|
return "Event: Unknown Class " + EventClass.ToString() + " kind: " + _eventKind.ToString();
|
||||||
|
|
|
@ -12,8 +12,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
|
public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
|
||||||
{
|
{
|
||||||
GraphicsMode gfx = new GraphicsMode((IntPtr)1, color, depth, stencil, samples,
|
GraphicsMode gfx = new GraphicsMode((IntPtr)1, color, depth, stencil, samples, accum, buffers, stereo);
|
||||||
accum, buffers, stereo);
|
|
||||||
|
|
||||||
System.Diagnostics.Debug.Print("Created dummy graphics mode.");
|
System.Diagnostics.Debug.Print("Created dummy graphics mode.");
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,13 @@ namespace OpenTK.Platform.MacOS
|
||||||
{
|
{
|
||||||
static object display_lock = new object();
|
static object display_lock = new object();
|
||||||
|
|
||||||
static Dictionary<DisplayDevice, IntPtr> displayMap =
|
static Dictionary<DisplayDevice, IntPtr> displayMap = new Dictionary<DisplayDevice, IntPtr>();
|
||||||
new Dictionary<DisplayDevice, IntPtr>();
|
|
||||||
|
|
||||||
static IntPtr mainDisplay;
|
static IntPtr mainDisplay;
|
||||||
internal static IntPtr MainDisplay { get { return mainDisplay; } }
|
static internal IntPtr MainDisplay
|
||||||
|
{
|
||||||
|
get { return mainDisplay; }
|
||||||
|
}
|
||||||
|
|
||||||
static QuartzDisplayDeviceDriver()
|
static QuartzDisplayDeviceDriver()
|
||||||
{
|
{
|
||||||
|
@ -33,7 +35,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
fixed(IntPtr* displayPtr = displays)
|
fixed (IntPtr* displayPtr = displays)
|
||||||
{
|
{
|
||||||
CG.GetActiveDisplayList(maxDisplayCount, displayPtr, out displayCount);
|
CG.GetActiveDisplayList(maxDisplayCount, displayPtr, out displayCount);
|
||||||
}
|
}
|
||||||
|
@ -71,9 +73,9 @@ namespace OpenTK.Platform.MacOS
|
||||||
{
|
{
|
||||||
CFDictionary dict = new CFDictionary(displayModes[j]);
|
CFDictionary dict = new CFDictionary(displayModes[j]);
|
||||||
|
|
||||||
int width = (int) dict.GetNumberValue("Width");
|
int width = (int)dict.GetNumberValue("Width");
|
||||||
int height = (int) dict.GetNumberValue("Height");
|
int height = (int)dict.GetNumberValue("Height");
|
||||||
int bpp = (int) dict.GetNumberValue("BitsPerPixel");
|
int bpp = (int)dict.GetNumberValue("BitsPerPixel");
|
||||||
double freq = dict.GetNumberValue("RefreshRate");
|
double freq = dict.GetNumberValue("RefreshRate");
|
||||||
bool current = currentMode.Ref == dict.Ref;
|
bool current = currentMode.Ref == dict.Ref;
|
||||||
|
|
||||||
|
@ -90,14 +92,12 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HIRect bounds = CG.DisplayBounds(currentDisplay);
|
HIRect bounds = CG.DisplayBounds(currentDisplay);
|
||||||
Rectangle newRect = new Rectangle(
|
Rectangle newRect = new Rectangle((int)bounds.Origin.X, (int)bounds.Origin.Y, (int)bounds.Size.Width, (int)bounds.Size.Height);
|
||||||
(int)bounds.Origin.X, (int)bounds.Origin.Y, (int)bounds.Size.Width, (int)bounds.Size.Height);
|
|
||||||
|
|
||||||
Debug.Print("Display {0} bounds: {1}", i, newRect);
|
Debug.Print("Display {0} bounds: {1}", i, newRect);
|
||||||
|
|
||||||
DisplayDevice opentk_dev =
|
DisplayDevice opentk_dev = new DisplayDevice(opentk_dev_current_res, primary, opentk_dev_available_res, newRect);
|
||||||
new DisplayDevice(opentk_dev_current_res, primary, opentk_dev_available_res, newRect);
|
|
||||||
|
|
||||||
displayMap.Add(opentk_dev, currentDisplay);
|
displayMap.Add(opentk_dev, currentDisplay);
|
||||||
}
|
}
|
||||||
|
@ -107,13 +107,13 @@ namespace OpenTK.Platform.MacOS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static IntPtr HandleTo(DisplayDevice displayDevice)
|
static internal IntPtr HandleTo(DisplayDevice displayDevice)
|
||||||
{
|
{
|
||||||
if (displayMap.ContainsKey(displayDevice))
|
if (displayMap.ContainsKey(displayDevice))
|
||||||
return displayMap[displayDevice];
|
return displayMap[displayDevice];
|
||||||
else
|
else
|
||||||
return IntPtr.Zero;
|
return IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IDisplayDeviceDriver Members
|
#region IDisplayDeviceDriver Members
|
||||||
|
|
||||||
|
@ -142,10 +142,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
int bpp = (int)dict.GetNumberValue("BitsPerPixel");
|
int bpp = (int)dict.GetNumberValue("BitsPerPixel");
|
||||||
double freq = dict.GetNumberValue("RefreshRate");
|
double freq = dict.GetNumberValue("RefreshRate");
|
||||||
|
|
||||||
if (width == resolution.Width &&
|
if (width == resolution.Width && height == resolution.Height && bpp == resolution.BitsPerPixel && System.Math.Abs(freq - resolution.RefreshRate) < 1e-6)
|
||||||
height == resolution.Height &&
|
|
||||||
bpp == resolution.BitsPerPixel &&
|
|
||||||
System.Math.Abs(freq - resolution.RefreshRate) < 1e-6)
|
|
||||||
{
|
{
|
||||||
if (displaysCaptured.Contains(display) == false)
|
if (displaysCaptured.Contains(display) == false)
|
||||||
{
|
{
|
||||||
|
@ -183,5 +180,5 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue