Merge branch 'master' into listEnumTest

This commit is contained in:
Quajak 2020-07-17 11:43:14 +02:00 committed by GitHub
commit cbde32639f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 131 additions and 9 deletions

File diff suppressed because one or more lines are too long

View file

@ -76,19 +76,35 @@ namespace Cosmos.HAL.Drivers
/// <param name="bpp">BPP (color depth).</param>
public VBEDriver(ushort xres, ushort yres, ushort bpp)
{
if (VBE.IsAvailable())
PCIDevice videocard;
if (VBE.IsAvailable()) //VBE VESA Enabled Mulitboot Parsing
{
Global.mDebugger.SendInternal($"Creating VBE VESA driver with Mode {xres}*{yres}@{bpp}");
IO.LinearFrameBuffer = new MemoryBlock(VBE.getLfbOffset(), (uint)xres * yres * (uint)(bpp / 8));
lastbuffer = new ManagedMemoryBlock((uint)xres * yres * (uint)(bpp / 8));
}
else
else if (ISAModeAvailable()) //Bochs Graphics Adaptor ISA Mode
{
Global.mDebugger.SendInternal($"Creating VBE BGA driver with Mode {xres}*{yres}@{bpp}");
Global.mDebugger.SendInternal($"Creating VBE BGA driver with Mode {xres}*{yres}@{bpp}.");
IO.LinearFrameBuffer = new MemoryBlock(0xE0000000, 1920 * 1200 * 4);
lastbuffer = new ManagedMemoryBlock(1920 * 1200 * 4);
VBESet(xres, yres, bpp);
}
else if (((videocard = HAL.PCI.GetDevice(VendorID.VirtualBox, DeviceID.VBVGA)) != null) || //VirtualBox Video Adapter PCI Mode
((videocard = HAL.PCI.GetDevice(VendorID.Bochs, DeviceID.BGA)) != null)) // Bochs Graphics Adaptor PCI Mode
{
Global.mDebugger.SendInternal($"Creating VBE BGA driver with Mode {xres}*{yres}@{bpp}. Framebuffer address=" + videocard.BAR0);
IO.LinearFrameBuffer = new MemoryBlock(videocard.BAR0, 1920 * 1200 * 4);
lastbuffer = new ManagedMemoryBlock(1920 * 1200 * 4);
VBESet(xres, yres, bpp);
}
else
{
throw new Exception("No supported VBE device found.");
}
}
/// <summary>
@ -107,7 +123,7 @@ namespace Cosmos.HAL.Drivers
IO.VbeIndex.Word = (ushort)index;
return IO.VbeData.Word;
}
public static bool Available()
public static bool ISAModeAvailable()
{
//This code wont work as long as Bochs uses BGA ISA, since it wont discover it in PCI
#if false

View file

@ -74,6 +74,8 @@ namespace Cosmos.HAL
public readonly uint slot;
public readonly uint function;
public readonly uint BAR0;
public readonly ushort VendorID;
public readonly ushort DeviceID;
@ -115,6 +117,8 @@ namespace Cosmos.HAL
VendorID = ReadRegister16((byte)Config.VendorID);
DeviceID = ReadRegister16((byte)Config.DeviceID);
BAR0 = ReadRegister32((byte)Config.BAR0);
//Command = ReadRegister16((byte)Config.Command);
//Status = ReadRegister16((byte)Config.Status);

View file

@ -856,6 +856,26 @@ namespace Cosmos.System.Graphics
}
}
/// <summary>
/// Draw image with alpha channel.
/// </summary>
/// <param name="image">Image to draw.</param>
/// <param name="x">X coordinate.</param>
/// <param name="y">Y coordinate.</param>
/// <exception cref="Exception">Thrown on memory access violation.</exception>
/// <exception cref="ArgumentOutOfRangeException">Thrown on fatal error.</exception>
public void DrawImageAlpha(Image image, int x, int y)
{
for (int _x = 0; _x < image.Width; _x++)
{
for (int _y = 0; _y < image.Height; _y++)
{
Global.mDebugger.SendInternal(image.rawData[_x + _y * image.Width]);
DrawPoint(new Pen(Color.FromArgb(image.rawData[_x + _y * image.Width])), x + _x, y + _y);
}
}
}
/// <summary>
/// Draw image.
/// </summary>
@ -868,6 +888,18 @@ namespace Cosmos.System.Graphics
DrawImage(image, point.X, point.Y);
}
/// <summary>
/// Draw image with alpha channel.
/// </summary>
/// <param name="image">Image to draw.</param>
/// <param name="point">Point of the top left corner of the image.</param>
/// <exception cref="Exception">Thrown on memory access violation.</exception>
/// <exception cref="ArgumentOutOfRangeException">Thrown on fatal error.</exception>
public void DrawImageAlpha(Image image, Point point)
{
DrawImageAlpha(image, point.X, point.Y);
}
/// <summary>
/// Draw string.
/// </summary>
@ -1021,7 +1053,7 @@ namespace Cosmos.System.Graphics
/// </summary>
/// <param name="x1">X coordinate.</param>
/// <param name="y1">Y coordinate.</param>
/// /// <param name="x2">X coordinate.</param>
/// <param name="x2">X coordinate.</param>
/// <param name="y2">Y coordinate.</param>
protected void TrimLine(ref int x1, ref int y1, ref int x2, ref int y2)
{
@ -1111,5 +1143,19 @@ namespace Cosmos.System.Graphics
x2 = (int)x2_out; y2 = (int)y2_out;
}
/// <summary>
/// Calculate new Color from back Color with alpha
/// </summary>
/// <param name="to">Color to calculate.</param>
/// <param name="from">Color used to calculate.</param>
/// <param name="alpha">Alpha amount.</param>
public Color AlphaBlend(Color to, Color from, byte alpha)
{
byte R = (byte)((to.R * alpha + from.R * (255 - alpha)) >> 8);
byte G = (byte)((to.G * alpha + from.G * (255 - alpha)) >> 8);
byte B = (byte)((to.B * alpha + from.B * (255 - alpha)) >> 8);
return Color.FromArgb(R, G, B);
}
}
}

View file

@ -1,4 +1,5 @@
//#define COSMOSDEBUG
using Cosmos.Core;
using Cosmos.HAL;
using Cosmos.HAL.Drivers;
@ -47,7 +48,7 @@ namespace Cosmos.System.Graphics
/// <returns></returns>
public static bool BGAExists()
{
return VBEDriver.Available();
return VBEDriver.ISAModeAvailable();
}
/// <summary>
@ -66,7 +67,7 @@ namespace Cosmos.System.Graphics
{
return new SVGAIICanvas();
}
else if (BGAExists() || PCI.GetDevice((VendorID)0x80EE, (DeviceID)0xBEEF) != null || Core.VBE.IsAvailable())
if (VBEAvailable())
{
return new VBECanvas();
}
@ -76,6 +77,34 @@ namespace Cosmos.System.Graphics
}
}
/// <summary>
/// Checks is VBE is supported exists
/// </summary>
/// <returns></returns>
private static bool VBEAvailable()
{
if (BGAExists())
{
return true;
}
else if (PCI.Exists(VendorID.VirtualBox, DeviceID.VBVGA))
{
return true;
}
else if (PCI.Exists(VendorID.Bochs, DeviceID.BGA))
{
return true;
}
else if (VBE.IsAvailable())
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// Get video driver.
/// </summary>
@ -88,7 +117,7 @@ namespace Cosmos.System.Graphics
{
return new SVGAIICanvas(mode);
}
else if (BGAExists() || PCI.GetDevice((VendorID)0x80EE, (DeviceID)0xBEEF) != null || Core.VBE.IsAvailable())
if (VBEAvailable())
{
return new VBECanvas(mode);
}

View file

@ -92,6 +92,15 @@ namespace Cosmos.System.Graphics
{
Color xColor = aPen.Color;
if (xColor.A == 0)
{
return;
}
else if (xColor.A < 255)
{
xColor = AlphaBlend(xColor, GetPointColor(aX, aY), xColor.A);
}
mSVGAIIDebugger.SendInternal($"Drawing point to x:{aX}, y:{aY} with {xColor.Name} Color");
_xSVGADriver.SetPixel((uint)aX, (uint)aY, (uint)xColor.ToArgb());
mSVGAIIDebugger.SendInternal($"Done drawing point");

View file

@ -226,10 +226,20 @@ namespace Cosmos.System.Graphics
switch (Mode.ColorDepth)
{
case ColorDepth.ColorDepth32:
offset = (uint)GetPointOffset(aX, aY);
Global.mDebugger.SendInternal($"Drawing Point of color {color} at offset {offset}");
if (color.A == 0)
{
return;
}
else if (color.A < 255)
{
color = AlphaBlend(color, GetPointColor(aX, aY), color.A);
}
_VBEDriver.SetVRAM(offset, color.B);
_VBEDriver.SetVRAM(offset + 1, color.G);
_VBEDriver.SetVRAM(offset + 2, color.R);