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 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); }
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; }
IntPtr GetQuartzDevice(CarbonWindow window) { return(CG.CGMainDisplayID()); }