public override void Redraw(Bitmap framebuffer, Rectangle r) { using (FastBitmap bmp = new FastBitmap(framebuffer, true, true)) { IntPtr scan0 = bmp.Scan0; int size = bmp.Width * bmp.Height * 4; IntPtr colorSpace = OSX.API.CGColorSpaceCreateDeviceRGB(); IntPtr provider = OSX.API.CGDataProviderCreateWithData(IntPtr.Zero, scan0, size, IntPtr.Zero); const uint flags = 4 | (2 << 12); IntPtr image = OSX.API.CGImageCreate(bmp.Width, bmp.Height, 8, 32, bmp.Stride, colorSpace, flags, provider, IntPtr.Zero, 0, 0); IntPtr context = IntPtr.Zero; OSStatus err = OSX.API.QDBeginCGContext(windowPort, ref context); OSX.API.CheckReturn(err); // TODO: only redraw changed region OSX.HIRect rect = new OSX.HIRect(); rect.Origin.X = 0; rect.Origin.Y = 0; rect.Size.X = bmp.Width; rect.Size.Y = bmp.Height; OSX.API.CGContextDrawImage(context, rect, image); OSX.API.CGContextSynchronize(context); err = OSX.API.QDEndCGContext(windowPort, ref context); OSX.API.CheckReturn(err); OSX.API.CGImageRelease(image); OSX.API.CGDataProviderRelease(provider); OSX.API.CGColorSpaceRelease(colorSpace); } }
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; }
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 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(); } }
unsafe static extern void DisplayBounds(out HIRect rect, IntPtr display);
public extern static void CGContextDrawImage(IntPtr context, HIRect rect, IntPtr image);