//#define COSMOSDEBUG
using System;
using System.Collections.Generic;
using System.Drawing;
using Cosmos.Debug.Kernel;
using Cosmos.HAL.Drivers.PCI.Video;
namespace Cosmos.System.Graphics
{
///
/// SVGAIIScreen class. Used to draw ractengales to the screen. See also: .
///
public class SVGAIIScreen : Canvas
{
///
/// Default graphics mode.
///
private static readonly Mode DefaultMode = new Mode(1024, 768, ColorDepth.ColorDepth32);
///
/// Debugger.
///
private static readonly Debugger Debugger = new Debugger("System", "SVGAIIScreen");
///
/// Graphics mode.
///
private Mode _mode;
///
/// VMWare SVGA 2 driver.
///
private readonly VMWareSVGAII xSVGAIIDriver;
///
/// Create new inctanse of the class.
///
/// Thrown if default graphics mode is not suppoted.
public SVGAIIScreen()
: this(DefaultMode)
{
}
///
/// Create new inctanse of the class.
///
/// A graphics mode.
/// Thrown if mode is not suppoted.
public SVGAIIScreen(Mode aMode)
{
Debugger.SendInternal($"Called ctor with mode {aMode}");
ThrowIfModeIsNotValid(aMode);
xSVGAIIDriver = new VMWareSVGAII();
Mode = aMode;
}
///
/// Get and set graphics mode.
///
/// (set) Thrown if mode is not suppoted.
public override Mode Mode
{
get => _mode;
set
{
_mode = value;
Debugger.SendInternal($"Called Mode set property with mode {_mode}");
SetGraphicsMode(_mode);
}
}
///
/// Override canvas dufault graphics mode.
///
public override Mode DefaultGraphicMode => DefaultMode;
///
/// Draw point.
///
/// Pen to draw with.
/// X coordinate.
/// Y coordinate.
/// Thrown on memory access violation.
public override void DrawPoint(Pen pen, int x, int y)
{
Color xColor = pen.Color;
Debugger.SendInternal($"Drawing point to x:{x}, y:{y} with {xColor.Name} Color");
xSVGAIIDriver.SetPixel((uint)x, (uint)y, (uint)xColor.ToArgb());
Debugger.SendInternal($"Done drawing point");
/* No need to refresh all the screen to make the point appear on Screen! */
//xSVGAIIDriver.Update((uint)x, (uint)y, (uint)mode.Columns, (uint)mode.Rows);
xSVGAIIDriver.Update((uint)x, (uint)y, 1, 1);
}
///
/// Draw array of colors.
/// Not implemented.
///
/// Array of colors.
/// X coordinate.
/// Y coordinate.
/// Width.
/// Height.
/// Thrown always.
public override void DrawArray(Color[] colors, int x, int y, int width, int height)
{
throw new NotImplementedException();
//xSVGAIIDriver.
}
///
/// Draw point.
/// Not implemented.
///
/// Pen to draw with.
/// X coordinate.
/// Y coordinate.
/// Thrown always (only int coordinates supported).
public override void DrawPoint(Pen pen, float x, float y)
{
//xSVGAIIDriver.
throw new NotImplementedException();
}
///
/// Draw filled rectangle.
///
/// Pen to draw with.
/// starting X coordinate.
/// starting Y coordinate.
/// Width.
/// Height.
/// Thrown on memory access violation.
/// Thrown if VMWare SVGA 2 has no rectange copy capability
public override void DrawFilledRectangle(Pen pen, int x_start, int y_start, int width, int height)
{
xSVGAIIDriver.Fill((uint)x_start, (uint)y_start, (uint)width, (uint)height, (uint)pen.Color.ToArgb());
}
//public override IReadOnlyList AvailableModes { get; } = new List
///
/// Available SVGA 2 supported video modes.
///
/// SD:
///
/// - 320x200x32.
/// - 320x240x32.
/// - 640x480x32.
/// - 720x480x32.
/// - 800x600x32.
/// - 1024x768x32.
/// - 1152x768x32.
///
///
///
/// HD:
///
/// - 1280x720x32.
/// - 1280x768x32.
/// - 1280x800x32.
/// - 1280x1024x32.
///
///
///
/// HDR:
///
/// - 1360x768x32.
/// - 1366x768x32.
/// - 1440x900x32.
/// - 1400x1050x32.
/// - 1600x1200x32.
/// - 1680x1050x32.
///
///
///
/// HDTV:
///
/// - 1920x1080x32.
/// - 1920x1200x32.
///
///
///
/// 2K:
///
/// - 2048x1536x32.
/// - 2560x1080x32.
/// - 2560x1600x32.
/// - 2560x2048x32.
/// - 3200x2048x32.
/// - 3200x2400x32.
/// - 3840x2400x32.
///
///
///
public override List AvailableModes { get; } = new List
{
/* VmWare maybe supports 16 bit resolutions but CGS not yet (we should need to do RGB32->RGB16 conversion) */
#if false
/* 16-bit Depth Resolutions*/
/* SD Resolutions */
new Mode(320, 200, ColorDepth.ColorDepth16),
new Mode(320, 240, ColorDepth.ColorDepth16),
new Mode(640, 480, ColorDepth.ColorDepth16),
new Mode(720, 480, ColorDepth.ColorDepth16),
new Mode(800, 600, ColorDepth.ColorDepth16),
new Mode(1024, 768, ColorDepth.ColorDepth16),
new Mode(1152, 768, ColorDepth.ColorDepth16),
/* Old HD-Ready Resolutions */
new Mode(1280, 720, ColorDepth.ColorDepth16),
new Mode(1280, 768, ColorDepth.ColorDepth16),
new Mode(1280, 800, ColorDepth.ColorDepth16), // WXGA
new Mode(1280, 1024, ColorDepth.ColorDepth16), // SXGA
/* Better HD-Ready Resolutions */
new Mode(1360, 768, ColorDepth.ColorDepth16),
new Mode(1366, 768, ColorDepth.ColorDepth16), // Original Laptop Resolution
new Mode(1440, 900, ColorDepth.ColorDepth16), // WXGA+
new Mode(1400, 1050, ColorDepth.ColorDepth16), // SXGA+
new Mode(1600, 1200, ColorDepth.ColorDepth16), // UXGA
new Mode(1680, 1050, ColorDepth.ColorDepth16), // WXGA++
/* HDTV Resolutions */
new Mode(1920, 1080, ColorDepth.ColorDepth16),
new Mode(1920, 1200, ColorDepth.ColorDepth16), // WUXGA
/* 2K Resolutions */
new Mode(2048, 1536, ColorDepth.ColorDepth16), // QXGA
new Mode(2560, 1080, ColorDepth.ColorDepth16), // UW-UXGA
new Mode(2560, 1600, ColorDepth.ColorDepth16), // WQXGA
new Mode(2560, 2048, ColorDepth.ColorDepth16), // QXGA+
new Mode(3200, 2048, ColorDepth.ColorDepth16), // WQXGA+
new Mode(3200, 2400, ColorDepth.ColorDepth16), // QUXGA
new Mode(3840, 2400, ColorDepth.ColorDepth16), // WQUXGA
#endif
/* 32-bit Depth Resolutions*/
/* SD Resolutions */
new Mode(320, 200, ColorDepth.ColorDepth32),
new Mode(320, 240, ColorDepth.ColorDepth32),
new Mode(640, 480, ColorDepth.ColorDepth32),
new Mode(720, 480, ColorDepth.ColorDepth32),
new Mode(800, 600, ColorDepth.ColorDepth32),
new Mode(1024, 768, ColorDepth.ColorDepth32),
new Mode(1152, 768, ColorDepth.ColorDepth32),
/* Old HD-Ready Resolutions */
new Mode(1280, 720, ColorDepth.ColorDepth32),
new Mode(1280, 768, ColorDepth.ColorDepth32),
new Mode(1280, 800, ColorDepth.ColorDepth32), // WXGA
new Mode(1280, 1024, ColorDepth.ColorDepth32), // SXGA
/* Better HD-Ready Resolutions */
new Mode(1360, 768, ColorDepth.ColorDepth32),
new Mode(1366, 768, ColorDepth.ColorDepth32), // Original Laptop Resolution
new Mode(1440, 900, ColorDepth.ColorDepth32), // WXGA+
new Mode(1400, 1050, ColorDepth.ColorDepth32), // SXGA+
new Mode(1600, 1200, ColorDepth.ColorDepth32), // UXGA
new Mode(1680, 1050, ColorDepth.ColorDepth32), // WXGA++
/* HDTV Resolutions */
new Mode(1920, 1080, ColorDepth.ColorDepth32),
new Mode(1920, 1200, ColorDepth.ColorDepth32), // WUXGA
/* 2K Resolutions */
new Mode(2048, 1536, ColorDepth.ColorDepth32), // QXGA
new Mode(2560, 1080, ColorDepth.ColorDepth32), // UW-UXGA
new Mode(2560, 1600, ColorDepth.ColorDepth32), // WQXGA
new Mode(2560, 2048, ColorDepth.ColorDepth32), // QXGA+
new Mode(3200, 2048, ColorDepth.ColorDepth32), // WQXGA+
new Mode(3200, 2400, ColorDepth.ColorDepth32), // QUXGA
new Mode(3840, 2400, ColorDepth.ColorDepth32), // WQUXGA
};
///
/// Set graphics mode.
///
/// A mode.
/// Thrown if mode is not suppoted.
private void SetGraphicsMode(Mode aMode)
{
ThrowIfModeIsNotValid(aMode);
var xWidth = (uint)aMode.Columns;
var xHeight = (uint)aMode.Rows;
var xColorDepth = (uint)aMode.ColorDepth;
xSVGAIIDriver.SetMode(xWidth, xHeight, xColorDepth);
}
///
/// Clear screen to specified color.
///
/// Color.
/// Thrown on memory access violation.
/// Thrown if VMWare SVGA 2 has no rectange copy capability
public override void Clear(Color color)
{
xSVGAIIDriver.Fill(0, 0, (uint)Mode.Columns, (uint)Mode.Rows, (uint)color.ToArgb());
}
///
/// Get pixel color.
///
/// A X coordinate.
/// A Y coordinate.
/// Color value.
/// Thrown on memory access violation.
public Color GetPixel(int aX, int aY)
{
var xColorARGB = xSVGAIIDriver.GetPixel((uint)aX, (uint)aX);
var xColor = Color.FromArgb((int)xColorARGB);
return xColor;
}
///
/// Set cursor.
///
/// Visible.
/// A X coordinate.
/// A Y coordinate.
public void SetCursor(bool aVisible, int aX, int aY)
{
xSVGAIIDriver.SetCursor(aVisible, (uint)aX, (uint)aY);
}
///
/// Create cursor.
///
public void CreateCursor()
{
xSVGAIIDriver.DefineCursor();
}
///
/// Copy pixel
///
/// A source X coordinate.
/// A source Y coordinate.
/// A destination X coordinate.
/// A destination Y coordinate.
/// A width.
/// A height.
/// Thrown if VMWare SVGA 2 has no rectange copy capability
public void CopyPixel(int aX, int aY, int aNewX, int aNewY, int aWidth = 1, int aHeight = 1)
{
xSVGAIIDriver.Copy((uint)aX, (uint)aY, (uint)aNewX, (uint)aNewY, (uint)aWidth, (uint)aHeight);
}
///
/// Move pixel
///
/// A X coordinate.
/// A Y coordinate.
/// A new X coordinate.
/// A new Y coordinate.
/// Thrown if VMWare SVGA 2 has no rectange copy capability
/// Thrown on memory access violation.
public void MovePixel(int aX, int aY, int aNewX, int aNewY)
{
xSVGAIIDriver.Copy((uint)aX, (uint)aY, (uint)aNewX, (uint)aNewY, 1, 1);
xSVGAIIDriver.SetPixel((uint)aX, (uint)aY, 0);
}
///
/// Get point color.
///
/// X coordinate.
/// Y coordinate.
/// Color value.
/// Thrown on memory access violation.
public override Color GetPointColor(int x, int y)
{
return Color.FromArgb((int)xSVGAIIDriver.GetPixel((uint)x, (uint)y));
}
}
}