//#define COSMOSDEBUG using Cosmos.HAL; using Cosmos.HAL.Drivers; namespace Cosmos.System.Graphics { /// /// FullScreenCanvas class. Used to set and get full screen canvas. /// public static class FullScreenCanvas { /// /// Boolean value whether CGS is in use or not /// public static bool IsInUse = false; /// /// Disables the specified Graphics Driver used and returns to VGA text mode 80x25 /// public static void Disable() { if (IsInUse) { _VideoDriver.Disable(); VGAScreen.SetTextMode(VGADriver.TextSize.Size80x25); } } /// /// List of all video drivers (BGA, /// private enum VideoDriver { VMWareSVGAIIDriver, VBEDriver, VGADriver } /// /// SVGA 2 device. /// private static PCIDevice _SVGAIIDevice = PCI.GetDevice(VendorID.VMWare, DeviceID.SVGAIIAdapter); /// /// Checks whether the Bochs Graphics Adapter exists (not limited to Bochs) /// /// public static bool BGAExists() { return VBEDriver.Available(); } /// /// Video driver. /// private static Canvas _VideoDriver = null; /// /// Get video driver. /// /// Canvas value. /// Thrown if default graphics mode is not suppoted. private static Canvas GetVideoDriver() { if (_SVGAIIDevice != null && PCI.Exists(_SVGAIIDevice)) { return new SVGAIICanvas(); } else if (BGAExists() || PCI.GetDevice((VendorID)0x80EE, (DeviceID)0xBEEF) != null || Core.VBE.IsAvailable()) { return new VBECanvas(); } else { return new VGACanvas(); } } /// /// Get video driver. /// /// Mode. /// Canvas value. /// Thrown if graphics mode is not suppoted. private static Canvas GetVideoDriver(Mode mode) { if (_SVGAIIDevice != null && PCI.Exists(_SVGAIIDevice)) { return new SVGAIICanvas(mode); } else if (BGAExists() || PCI.GetDevice((VendorID)0x80EE, (DeviceID)0xBEEF) != null || Core.VBE.IsAvailable()) { return new VBECanvas(mode); } else { return new VGACanvas(mode); } } /// /// Get full screen canvas. /// /// Canvas value. /// Thrown if default graphics mode is not suppoted. public static Canvas GetFullScreenCanvas() { Global.mDebugger.SendInternal($"GetFullScreenCanvas() with default mode"); if (_VideoDriver == null) { Global.mDebugger.SendInternal($"_VideoDriver is null creating new object"); _VideoDriver = GetVideoDriver(); } else { Global.mDebugger.SendInternal($"_VideoDriver is NOT null using the old one changing mode to DefaultMode"); _VideoDriver.Mode = _VideoDriver.DefaultGraphicMode; } return _VideoDriver; } /// /// Get full screen canvas. /// /// Mode. /// Canvas value. /// Thrown if graphics mode is not suppoted. public static Canvas GetFullScreenCanvas(Mode mode) { Global.mDebugger.SendInternal($"GetFullScreenCanvas() with mode" + mode); if (_VideoDriver == null) { _VideoDriver = GetVideoDriver(mode); } else { _VideoDriver.Mode = mode; } return _VideoDriver; } } }