public override sealed bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution) { IntPtr num1 = QuartzDisplayDeviceDriver.HandleTo(device); IntPtr num2 = CG.DisplayCurrentMode(num1); if (!this.storedModes.ContainsKey(num1)) { this.storedModes.Add(num1, num2); } CFArray cfArray = new CFArray(CG.DisplayAvailableModes(num1)); for (int index = 0; index < cfArray.Count; ++index) { CFDictionary cfDictionary = new CFDictionary(cfArray[index]); int num3 = (int)cfDictionary.GetNumberValue("Width"); int num4 = (int)cfDictionary.GetNumberValue("Height"); int num5 = (int)cfDictionary.GetNumberValue("BitsPerPixel"); double numberValue = cfDictionary.GetNumberValue("RefreshRate"); if (num3 == resolution.Width && num4 == resolution.Height && (num5 == resolution.BitsPerPixel && Math.Abs(numberValue - (double)resolution.RefreshRate) < 1E-06)) { if (!this.displaysCaptured.Contains(num1)) { int num6 = (int)CG.DisplayCapture(num1); } CG.DisplaySwitchToMode(num1, cfArray[index]); return(true); } } return(false); }
private void RestoreWindowState() { suppressResize++; if (windowState == WindowState.Fullscreen) { SetMenuVisible(true); if (MacOSFactory.ExclusiveFullscreen) { CG.DisplayReleaseAll(); Cocoa.SendVoid(windowInfo.Handle, selSetLevel, normalLevel); } RestoreBorder(); InternalBounds = previousBounds; } else if (windowState == WindowState.Maximized) { RestoreBorder(); InternalBounds = previousBounds; } else if (windowState == WindowState.Minimized) { Cocoa.SendVoid(windowInfo.Handle, selDeminiaturize, windowInfo.Handle); } windowState = WindowState.Normal; suppressResize--; }
protected virtual void Dispose(bool disposing) { if (mIsDisposed) { return; } Debug.Print("Disposing of CarbonGLNative window."); CursorVisible = true; API.DisposeWindow(window.Handle); mIsDisposed = true; mExists = false; CG.SetLocalEventsSuppressionInterval(0.25); if (disposing) { mWindows.Remove(window.Handle); window.Dispose(); window = null; } DisposeUPP(); Disposed(this, EventArgs.Empty); }
internal void SetFullScreen(CarbonWindow wind, out int width, out int height) { int displayWidth = wind.Display.Bounds.Width; int displayHeight = wind.Display.Bounds.Height; Debug.Print("Switching to full screen {0}x{1} on context {2}", displayWidth, displayHeight, ContextHandle); CG.CGDisplayCapture(CG.CGMainDisplayID()); byte code = Agl.aglSetFullScreen(ContextHandle, displayWidth, displayHeight, 0, 0); Agl.CheckReturnValue(code, "aglSetFullScreen"); MakeCurrent(wind); width = displayWidth; height = displayHeight; // 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 // and redo it as fullscreen. if (!firstFullScreen) { firstFullScreen = true; UnsetFullScreen(wind); SetFullScreen(wind, out width, out height); } mIsFullscreen = true; }
internal void SetFullScreen(CarbonWindowInfo info, out int width, out int height) { CarbonGLNative wind = GetCarbonWindow(info); Debug.Print("Switching to full screen {0}x{1} on context {2}", wind.TargetDisplayDevice.Width, wind.TargetDisplayDevice.Height, Handle.Handle); CG.DisplayCapture(GetQuartzDevice(info)); Agl.aglSetFullScreen(Handle.Handle, wind.TargetDisplayDevice.Width, wind.TargetDisplayDevice.Height, 0, 0); MakeCurrent(info); width = wind.TargetDisplayDevice.Width; height = wind.TargetDisplayDevice.Height; // 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 // and redo it as fullscreen. if (firstFullScreen == false) { firstFullScreen = true; UnsetFullScreen(info); SetFullScreen(info, out width, out height); } mIsFullscreen = true; }
internal void UnsetFullScreen(CarbonWindowInfo windowInfo) { Agl.aglSetDrawable(this.Handle.Handle, IntPtr.Zero); int num1 = (int)Agl.aglUpdateContext(this.Handle.Handle); int num2 = (int)CG.DisplayRelease(this.GetQuartzDevice(windowInfo)); this.SetDrawable(windowInfo); this.mIsFullscreen = false; }
internal void UnsetFullScreen(CarbonWindowInfo windowInfo) { Debug.Print("Unsetting AGL fullscreen."); Agl.aglSetDrawable(Handle.Handle, IntPtr.Zero); Agl.aglUpdateContext(Handle.Handle); CG.DisplayRelease(GetQuartzDevice(windowInfo)); Debug.Print("Resetting drawable."); SetDrawable(windowInfo); mIsFullscreen = false; }
internal unsafe static void Init() { IntPtr display = CG.CGMainDisplayID(); DisplayDevice device = new DisplayDevice(); HIRect bounds = CG.CGDisplayBounds(display); device.Bounds = new Rectangle( (int)bounds.Origin.X, (int)bounds.Origin.Y, (int)bounds.Size.X, (int)bounds.Size.Y); device.BitsPerPixel = CG.CGDisplayBitsPerPixel(display); DisplayDevice.Default = device; }
void CreateContext(GraphicsMode mode, CarbonWindow wind, bool fullscreen) { int[] attribs = GetAttribs(mode, fullscreen); IntPtr pixelFormat; // Choose a pixel format with the attributes we specified. if (fullscreen) { IntPtr gdevice; IntPtr display = CG.CGMainDisplayID(); OSStatus status = API.DMGetGDeviceByDisplayID(display, out gdevice, false); if (status != OSStatus.NoError) { throw new MacOSException(status, "DMGetGDeviceByDisplayID failed."); } pixelFormat = Agl.aglChoosePixelFormat(ref gdevice, 1, attribs); int err = Agl.aglGetError(); if (err == Agl.AGL_BAD_PIXEL_FORMAT) { Debug.Print("Failed to create full screen pixel format."); Debug.Print("Trying again to create a non-fullscreen pixel format."); CreateContext(mode, wind, false); return; } } else { pixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, attribs); Agl.CheckReturnValue(0, "aglChoosePixelFormat"); } Debug.Print("Creating AGL context."); // create the context and share it with the share reference. ContextHandle = Agl.aglCreateContext(pixelFormat, IntPtr.Zero); Agl.CheckReturnValue(0, "aglCreateContext"); // Free the pixel format from memory. Agl.aglDestroyPixelFormat(pixelFormat); Agl.CheckReturnValue(0, "aglDestroyPixelFormat"); SetDrawable(wind); Update(wind); MakeCurrent(wind); Debug.Print("context: {0}", ContextHandle); }
public override sealed bool TryRestoreResolution(DisplayDevice device) { IntPtr index = QuartzDisplayDeviceDriver.HandleTo(device); if (!this.storedModes.ContainsKey(index)) { return(false); } CG.DisplaySwitchToMode(index, this.storedModes[index]); int num = (int)CG.DisplayRelease(index); this.displaysCaptured.Remove(index); return(true); }
public bool TryRestoreResolution(DisplayDevice device) { IntPtr display = displayMap[device]; if (storedModes.ContainsKey(display)) { Debug.Print("Restoring resolution."); CG.DisplaySwitchToMode(display, storedModes[display]); CG.DisplayRelease(display); displaysCaptured.Remove(display); return(true); } return(false); }
internal void UnsetFullScreen(CarbonWindow window) { Debug.Print("Unsetting AGL fullscreen."); byte code = Agl.aglSetDrawable(ContextHandle, IntPtr.Zero); Agl.CheckReturnValue(code, "aglSetDrawable"); code = Agl.aglUpdateContext(ContextHandle); Agl.CheckReturnValue(code, "aglUpdateContext"); CG.CGDisplayRelease(CG.CGMainDisplayID()); Debug.Print("Resetting drawable."); SetDrawable(window); mIsFullscreen = false; }
public unsafe QuartzDisplayDeviceDriver() { lock (QuartzDisplayDeviceDriver.display_lock) { IntPtr[] local_0 = new IntPtr[20]; int local_1; fixed(IntPtr *fixed_0 = local_0) { int temp_15 = (int)CG.GetActiveDisplayList(20, fixed_0, out local_1); } for (int local_3 = 0; local_3 < local_1; ++local_3) { IntPtr local_4 = local_0[local_3]; bool local_5 = local_3 == 0; CG.DisplayPixelsWide(local_4); CG.DisplayPixelsHigh(local_4); CFArray local_7 = new CFArray(CG.DisplayAvailableModes(local_4)); DisplayResolution local_8 = (DisplayResolution)null; List <DisplayResolution> local_9 = new List <DisplayResolution>(); CFDictionary local_11 = new CFDictionary(CG.DisplayCurrentMode(local_4)); for (int local_12 = 0; local_12 < local_7.Count; ++local_12) { CFDictionary local_13 = new CFDictionary(local_7[local_12]); int local_14 = (int)local_13.GetNumberValue("Width"); int local_15 = (int)local_13.GetNumberValue("Height"); int local_16 = (int)local_13.GetNumberValue("BitsPerPixel"); double local_17 = local_13.GetNumberValue("RefreshRate"); bool local_18 = local_11.Ref == local_13.Ref; DisplayResolution local_19 = new DisplayResolution(0, 0, local_14, local_15, local_16, (float)local_17); local_9.Add(local_19); if (local_18) { local_8 = local_19; } } HIRect local_20 = CG.DisplayBounds(local_4); Rectangle local_21 = new Rectangle((int)local_20.Origin.X, (int)local_20.Origin.Y, (int)local_20.Size.Width, (int)local_20.Size.Height); DisplayDevice local_22 = new DisplayDevice(local_8, local_5, (IEnumerable <DisplayResolution>)local_9, local_21, (object)local_4); this.AvailableDevices.Add(local_22); if (local_5) { this.Primary = local_22; } } } }
internal void SetFullScreen(CarbonWindowInfo info, out int width, out int height) { CarbonGLNative carbonWindow = this.GetCarbonWindow(info); int num = (int)CG.DisplayCapture(this.GetQuartzDevice(info)); Agl.aglSetFullScreen(this.Handle.Handle, carbonWindow.TargetDisplayDevice.Width, carbonWindow.TargetDisplayDevice.Height, 0, 0); this.MakeCurrent((IWindowInfo)info); width = carbonWindow.TargetDisplayDevice.Width; height = carbonWindow.TargetDisplayDevice.Height; if (!this.firstFullScreen) { this.firstFullScreen = true; this.UnsetFullScreen(info); this.SetFullScreen(info, out width, out height); } this.mIsFullscreen = true; }
public override bool TryRestoreResolution(DisplayDevice device) { var display = HandleTo(device); if (storedModes.ContainsKey(display)) { Debug.Print("Restoring resolution."); CG.DisplaySwitchToMode(display, storedModes[display]); //CG.DisplayRelease(display); displaysCaptured.Remove(display); return(true); } return(false); }
public bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution) { IntPtr display = displayMap[device]; IntPtr currentModePtr = CG.DisplayCurrentMode(display); if (storedModes.ContainsKey(display) == false) { storedModes.Add(display, currentModePtr); } IntPtr displayModesPtr = CG.DisplayAvailableModes(display); CFArray displayModes = new CFArray(displayModesPtr); for (int j = 0; j < displayModes.Count; j++) { CFDictionary dict = new CFDictionary(displayModes[j]); int width = (int)dict.GetNumberValue("Width"); int height = (int)dict.GetNumberValue("Height"); int bpp = (int)dict.GetNumberValue("BitsPerPixel"); double freq = dict.GetNumberValue("RefreshRate"); if (width == resolution.Width && height == resolution.Height && bpp == resolution.BitsPerPixel && System.Math.Abs(freq - resolution.RefreshRate) < 1e-6) { if (displaysCaptured.Contains(display) == false) { CG.DisplayCapture(display); } Debug.Print("Changing resolution to {0}x{1}x{2}@{3}.", width, height, bpp, freq); CG.DisplaySwitchToMode(display, displayModes[j]); return true; } } return false; }
protected virtual void Dispose(bool disposing) { if (this.mIsDisposed) { return; } this.CursorVisible = true; API.DisposeWindow(this.window.WindowRef); this.mIsDisposed = true; this.mExists = false; int num = (int)CG.SetLocalEventsSuppressionInterval(0.25); if (disposing) { CarbonGLNative.mWindows.Remove(this.window.WindowRef); this.window.Dispose(); this.window = (CarbonWindowInfo)null; } this.DisposeUPP(); this.Disposed((object)this, EventArgs.Empty); }
public override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution) { var display = HandleTo(device); var currentModePtr = CG.DisplayCurrentMode(display); if (storedModes.ContainsKey(display) == false) { storedModes.Add(display, currentModePtr); } var displayModesPtr = CG.DisplayAvailableModes(display); var displayModes = new CFArray(displayModesPtr); for (var j = 0; j < displayModes.Count; j++) { var dict = new CFDictionary(displayModes[j]); var width = (int)dict.GetNumberValue("Width"); var height = (int)dict.GetNumberValue("Height"); var bpp = (int)dict.GetNumberValue("BitsPerPixel"); var freq = dict.GetNumberValue("RefreshRate"); if (width == resolution.Width && height == resolution.Height && bpp == resolution.BitsPerPixel && Math.Abs(freq - resolution.RefreshRate) < 1e-6) { // if (displaysCaptured.Contains(display) == false) // { // CG.DisplayCapture(display); // } Debug.Print("Changing resolution to {0}x{1}x{2}@{3}.", width, height, bpp, freq); CG.DisplaySwitchToMode(display, displayModes[j]); return(true); } } return(false); }
private void SetCursorVisible(bool visible) { // If the mouse is outside the window and we want to hide it, // move it inside the window first. // Otherwise, if we are making the cursor visible again, // we place it in the same spot as reported in the current // MouseState to avoid sudden jumps. if (!visible && !Bounds.Contains(new Point(MouseState.X, MouseState.Y))) { Mouse.SetPosition( (Bounds.Left + Bounds.Right) / 2, (Bounds.Top + Bounds.Bottom) / 2); } else if (visible) { var p = PointToScreen(new Point(MouseState.X, MouseState.Y)); Mouse.SetPosition((int)p.X, (int)p.Y); } CG.AssociateMouseAndMouseCursorPosition(visible); Cocoa.SendVoid(NSCursor, visible ? selUnhide : selHide); }
public QuartzDisplayDeviceDriver() { lock (display_lock) { // To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice // we only allow settings to be set through its constructor. // Thus, we save all necessary parameters in temporary variables // and construct the device when every needed detail is available. // The main DisplayDevice constructor adds the newly constructed device // to the list of available devices. const int maxDisplayCount = 20; var displays = new IntPtr[maxDisplayCount]; int displayCount; unsafe { fixed(IntPtr *displayPtr = displays) { CG.GetActiveDisplayList(maxDisplayCount, displayPtr, out displayCount); } } Debug.Print("CoreGraphics reported {0} display(s).", displayCount); Debug.Indent(); for (var i = 0; i < displayCount; i++) { var currentDisplay = displays[i]; // according to docs, first element in the array is always the // main display. var primary = i == 0; // gets current settings var currentWidth = CG.DisplayPixelsWide(currentDisplay); var currentHeight = CG.DisplayPixelsHigh(currentDisplay); Debug.Print("Display {0} is at {1}x{2}", i, currentWidth, currentHeight); var displayModesPtr = CG.DisplayAvailableModes(currentDisplay); var displayModes = new CFArray(displayModesPtr); Debug.Print("Supports {0} display modes.", displayModes.Count); DisplayResolution opentk_dev_current_res = null; var opentk_dev_available_res = new List <DisplayResolution>(); var currentModePtr = CG.DisplayCurrentMode(currentDisplay); var currentMode = new CFDictionary(currentModePtr); for (var j = 0; j < displayModes.Count; j++) { var dict = new CFDictionary(displayModes[j]); var width = (int)dict.GetNumberValue("Width"); var height = (int)dict.GetNumberValue("Height"); var bpp = (int)dict.GetNumberValue("BitsPerPixel"); var freq = dict.GetNumberValue("RefreshRate"); var current = currentMode.Ref == dict.Ref; if (freq <= 0) { IntPtr displayLink; CV.DisplayLinkCreateWithCGDisplay(currentDisplay, out displayLink); var t = CV.DisplayLinkGetNominalOutputVideoRefreshPeriod(displayLink); if ((t.flags & (int)CV.TimeFlags.TimeIsIndefinite) != (int)CV.TimeFlags.TimeIsIndefinite) { freq = (double)t.timeScale / t.timeValue; } CV.DisplayLinkRelease(displayLink); } //if (current) Debug.Write(" * "); //else Debug.Write(" "); //Debug.Print("Mode {0} is {1}x{2}x{3} @ {4}.", j, width, height, bpp, freq); var thisRes = new DisplayResolution(0, 0, width, height, bpp, (float)freq); opentk_dev_available_res.Add(thisRes); if (current) { opentk_dev_current_res = thisRes; } } var bounds = CG.DisplayBounds(currentDisplay); var newRect = new Rectangle((int)bounds.Location.X, (int)bounds.Location.Y, (int)bounds.Size.Width, (int)bounds.Size.Height); Debug.Print("Display {0} bounds: {1}", i, newRect); var opentk_dev = new DisplayDevice(opentk_dev_current_res, primary, opentk_dev_available_res, newRect, currentDisplay); AvailableDevices.Add(opentk_dev); if (primary) { Primary = opentk_dev; } } Debug.Unindent(); } }
internal unsafe static void Init() { // To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice // we only allow settings to be set through its constructor. // Thus, we save all necessary parameters in temporary variables // and construct the device when every needed detail is available. // The main DisplayDevice constructor adds the newly constructed device // to the list of available devices. const int maxDisplayCount = 20; IntPtr[] displays = new IntPtr[maxDisplayCount]; int displayCount; fixed(IntPtr *displayPtr = displays) { CG.CGGetActiveDisplayList(maxDisplayCount, displayPtr, out displayCount); } Debug.Print("CoreGraphics reported {0} display(s).", displayCount); for (int i = 0; i < displayCount; i++) { IntPtr curDisplay = displays[i]; // according to docs, first element in the array is always the main display. bool primary = (i == 0); if (primary) { mainDisplay = curDisplay; } // gets current settings int currentWidth = CG.CGDisplayPixelsWide(curDisplay); int currentHeight = CG.CGDisplayPixelsHigh(curDisplay); Debug.Print("Display {0} is at {1}x{2}", i, currentWidth, currentHeight); IntPtr displayModesPtr = CG.CGDisplayAvailableModes(curDisplay); CFArray displayModes = new CFArray(displayModesPtr); Debug.Print("Supports {0} display modes.", displayModes.Count); DisplayResolution opentk_dev_current_res = null; IntPtr currentModePtr = CG.CGDisplayCurrentMode(curDisplay); CFDictionary currentMode = new CFDictionary(currentModePtr); for (int j = 0; j < displayModes.Count; j++) { CFDictionary dict = new CFDictionary(displayModes[j]); int width = (int)dict.GetNumberValue("Width"); int height = (int)dict.GetNumberValue("Height"); int bpp = (int)dict.GetNumberValue("BitsPerPixel"); double freq = dict.GetNumberValue("RefreshRate"); bool current = currentMode.DictRef == dict.DictRef; if (current) { opentk_dev_current_res = new DisplayResolution(width, height, bpp, (float)freq); } } HIRect bounds = CG.CGDisplayBounds(curDisplay); Rectangle newRect = new Rectangle( (int)bounds.Origin.X, (int)bounds.Origin.Y, (int)bounds.Size.X, (int)bounds.Size.Y); Debug.Print("Display {0} bounds: {1}", i, newRect); DisplayDevice opentk_dev = new DisplayDevice(opentk_dev_current_res, primary); opentk_dev.Bounds = newRect; opentk_dev.Metadata = curDisplay; } }
public QuartzDisplayDeviceDriver() { lock (display_lock) { // To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice // we only allow settings to be set through its constructor. // Thus, we save all necessary parameters in temporary variables // and construct the device when every needed detail is available. // The main DisplayDevice constructor adds the newly constructed device // to the list of available devices. const int maxDisplayCount = 20; IntPtr[] displays = new IntPtr[maxDisplayCount]; int displayCount; unsafe { fixed(IntPtr *displayPtr = displays) { CG.GetActiveDisplayList(maxDisplayCount, displayPtr, out displayCount); } } Debug.Print("CoreGraphics reported {0} display(s).", displayCount); Debug.Indent(); for (int i = 0; i < displayCount; i++) { IntPtr currentDisplay = displays[i]; // according to docs, first element in the array is always the // main display. bool primary = (i == 0); // gets current settings int currentWidth = CG.DisplayPixelsWide(currentDisplay); int currentHeight = CG.DisplayPixelsHigh(currentDisplay); Debug.Print("Display {0} is at {1}x{2}", i, currentWidth, currentHeight); 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>(); IntPtr currentModePtr = CG.DisplayCurrentMode(currentDisplay); CFDictionary currentMode = new CFDictionary(currentModePtr); for (int j = 0; j < displayModes.Count; j++) { CFDictionary dict = new CFDictionary(displayModes[j]); int width = (int)dict.GetNumberValue("Width"); int height = (int)dict.GetNumberValue("Height"); int bpp = (int)dict.GetNumberValue("BitsPerPixel"); double freq = dict.GetNumberValue("RefreshRate"); bool current = currentMode.Ref == dict.Ref; //if (current) Debug.Write(" * "); //else Debug.Write(" "); //Debug.Print("Mode {0} is {1}x{2}x{3} @ {4}.", j, width, height, bpp, freq); DisplayResolution thisRes = new DisplayResolution(0, 0, width, height, bpp, (float)freq); opentk_dev_available_res.Add(thisRes); if (current) { opentk_dev_current_res = thisRes; } } HIRect bounds = CG.DisplayBounds(currentDisplay); Rectangle newRect = new Rectangle((int)bounds.Origin.X, (int)bounds.Origin.Y, (int)bounds.Size.Width, (int)bounds.Size.Height); Debug.Print("Display {0} bounds: {1}", i, newRect); DisplayDevice opentk_dev = new DisplayDevice(opentk_dev_current_res, primary, opentk_dev_available_res, newRect, currentDisplay); AvailableDevices.Add(opentk_dev); if (primary) { Primary = opentk_dev; } } Debug.Unindent(); } }
void IMouseDriver2.SetPosition(double x, double y) { CG.SetLocalEventsSuppressionInterval(0.0); CG.WarpMouseCursorPosition(new Carbon.HIPoint(x, y)); }
void IMouseDriver2.SetPosition(double x, double y) { int num1 = (int)CG.SetLocalEventsSuppressionInterval(0.0); int num2 = (int)CG.WarpMouseCursorPosition(new HIPoint(x, y)); }
IntPtr GetQuartzDevice(CarbonWindow window) { return(CG.CGMainDisplayID()); }