Fixed MacOS initialization by returning IntPtr from CoreGraphics methods

instead of structures wrapping CoreFoundation types.
This commit is contained in:
kanato 2008-11-12 04:03:40 +00:00
parent e66d796bdb
commit 6e327798a3
5 changed files with 27 additions and 15 deletions

View file

@ -72,6 +72,7 @@ namespace OpenTK.Platform.MacOS.Carbon
else if (evt.EventClass == EventClass.AppleEvent)
{
// only event here is the apple event.
Debug.Print("Processing apple event.");
API.ProcessAppleEvent(inEvent);
}
@ -90,6 +91,7 @@ namespace OpenTK.Platform.MacOS.Carbon
static void MainWindowClosed(object sender, EventArgs e)
{
Debug.Print("Quitting application event loop.");
API.QuitApplicationEventLoop();
}

View file

@ -21,7 +21,7 @@ namespace OpenTK.Platform.MacOS.Carbon
// CGRect -> HIRect
[DllImport(appServices,EntryPoint="CGGetActiveDisplayList")]
internal static extern CGDisplayErr GetActiveDisplayList(int maxDisplays, IntPtr[] activeDspys, out int dspyCnt);
internal unsafe static extern CGDisplayErr GetActiveDisplayList(int maxDisplays, IntPtr* activeDspys, out int dspyCnt);
[DllImport(appServices,EntryPoint="CGMainDisplayID")]
internal static extern IntPtr MainDisplayID();
@ -33,7 +33,7 @@ namespace OpenTK.Platform.MacOS.Carbon
internal static extern int DisplayPixelsHigh(IntPtr display);
[DllImport(appServices,EntryPoint="CGDisplayCurrentMode")]
internal static extern CFDictionary DisplayCurrentMode(IntPtr display);
internal static extern IntPtr DisplayCurrentMode(IntPtr display);
[DllImport(appServices,EntryPoint="CGDisplayCapture")]
internal static extern CGDisplayErr DisplayCapture(IntPtr display);
@ -42,7 +42,7 @@ namespace OpenTK.Platform.MacOS.Carbon
internal static extern CGDisplayErr DisplayRelease(IntPtr display);
[DllImport(appServices, EntryPoint = "CGDisplayAvailableModes")]
internal static extern CFArray DisplayAvailableModes(IntPtr display);
internal static extern IntPtr DisplayAvailableModes(IntPtr display);
}
}

View file

@ -27,7 +27,7 @@ namespace OpenTK.Platform.MacOS
static MacOSKeyMap Keymap = new MacOSKeyMap();
IntPtr uppHandler;
string title = "New Window";
string title = "OpenTK Window";
short mWidth, mHeight;
bool mIsDisposed = false;
@ -94,8 +94,8 @@ namespace OpenTK.Platform.MacOS
{
if (uppHandler != IntPtr.Zero)
{
// API.RemoveEventHandler(uppHandler);
// API.DisposeEventHandlerUPP(uppHandler);
//API.RemoveEventHandler(uppHandler);
//API.DisposeEventHandlerUPP(uppHandler);
}
@ -109,7 +109,7 @@ namespace OpenTK.Platform.MacOS
Debug.Indent();
IntPtr windowRef = API.CreateNewWindow(@class, attrib, r);
//API.SetWindowTitle(windowRef, title);
API.SetWindowTitle(windowRef, title);
window = new CarbonWindowInfo(windowRef, true, false);
@ -129,7 +129,7 @@ namespace OpenTK.Platform.MacOS
ConnectEvents();
System.Diagnostics.Debug.Print("Attached events.");
System.Diagnostics.Debug.Print("Attached window events.");
}
public void Activate()
@ -187,7 +187,6 @@ namespace OpenTK.Platform.MacOS
API.ShowWindow(window.WindowRef);
API.RepositionWindow(window.WindowRef, parent, WindowPositionMethod);
API.SelectWindow(window.WindowRef);
}
public void Hide()
{
@ -222,6 +221,7 @@ namespace OpenTK.Platform.MacOS
WeakReference reference = mWindows[userData];
CarbonGLNative window = (CarbonGLNative)reference.Target;
Debug.Print("Processing {0} event for {1}.", evt, window.window);
if (window == null)
{

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace OpenTK.Platform.MacOS
@ -59,6 +60,7 @@ namespace OpenTK.Platform.MacOS
if (ownHandle)
{
Debug.Print("Disposing window {0}.", windowRef);
Carbon.API.DisposeWindow(this.windowRef);
windowRef = IntPtr.Zero;
}

View file

@ -36,7 +36,13 @@ namespace OpenTK.Platform.MacOS
IntPtr[] displays = new IntPtr[maxDisplayCount];
int displayCount;
CG.GetActiveDisplayList(maxDisplayCount, displays, out displayCount);
unsafe
{
fixed(IntPtr* displayPtr = displays)
{
CG.GetActiveDisplayList(maxDisplayCount, displayPtr, out displayCount);
}
}
Debug.Print("CoreGraphics reported {0} displays.", displayCount);
Debug.Indent();
@ -54,12 +60,14 @@ namespace OpenTK.Platform.MacOS
int currentHeight = CG.DisplayPixelsHigh(currentDisplay);
Debug.Print("Display {0} is at {1}x{2}", i, currentWidth, currentHeight);
CFArray displayModes = CG.DisplayAvailableModes(currentDisplay);
IntPtr displayModesPtr = CG.DisplayAvailableModes(currentDisplay);
CFArray displayModes = new CFArray(displayModesPtr);
Debug.Print("Supports {0} display modes.", displayModes.Count);
DisplayResolution opentk_dev_current_res = null;
List<DisplayResolution> opentk_dev_available_res = new List<DisplayResolution>();
CFDictionary currentMode = CG.DisplayCurrentMode(currentDisplay);
IntPtr currentModePtr = CG.DisplayCurrentMode(currentDisplay);
CFDictionary currentMode = new CFDictionary(currentModePtr);
for (int j = 0; j < displayModes.Count; j++)
{