From ffca0df48ebfbd77be473193307b9b6b4150a7d9 Mon Sep 17 00:00:00 2001 From: fanoI Date: Sun, 17 Feb 2019 16:35:24 +0100 Subject: [PATCH] Fixes #1109 and #1078. The CGS test kernel is now enabled always. --- .../Cosmos.TestRunner.Full/TestKernelSets.cs | 3 +- Tests/Kernels/GraphicTest/Kernel.cs | 111 +++++++++--------- source/Cosmos.System2/Graphics/Canvas.cs | 19 +-- .../Graphics/FullScreenCanvas.cs | 3 + .../Cosmos.System2/Graphics/SVGAIIScreen.cs | 18 ++- source/Cosmos.System2/Graphics/VBEScreen.cs | 15 +-- 6 files changed, 90 insertions(+), 79 deletions(-) diff --git a/Tests/Cosmos.TestRunner.Full/TestKernelSets.cs b/Tests/Cosmos.TestRunner.Full/TestKernelSets.cs index af462a967..83ab5528e 100644 --- a/Tests/Cosmos.TestRunner.Full/TestKernelSets.cs +++ b/Tests/Cosmos.TestRunner.Full/TestKernelSets.cs @@ -29,8 +29,7 @@ namespace Cosmos.TestRunner.Full //yield return typeof(KernelGen3.Boot); - /* Please see the notes on the kernel itself before enabling it */ - //yield return typeof(GraphicTest.Kernel); + yield return typeof(GraphicTest.Kernel); /* Please see the notes on the kernel itself before enabling it */ //yield return typeof(ConsoleTest.Kernel); /* This is a bit slow and works only because ring check is disabled to decide if leave it enabled */ diff --git a/Tests/Kernels/GraphicTest/Kernel.cs b/Tests/Kernels/GraphicTest/Kernel.cs index 95afa6ec5..24945e7a0 100644 --- a/Tests/Kernels/GraphicTest/Kernel.cs +++ b/Tests/Kernels/GraphicTest/Kernel.cs @@ -6,14 +6,8 @@ using System.Drawing; using Point = Cosmos.System.Graphics.Point; /* - * Please note this is an atypical TestRunner: - * - no Assertion can be done - * - it cannot be executed automatically - * - * it exists to make easier tests while changing low level stuff (it would be better and faster to use the Demo kernel but - * sometimes it is a problem to make it see modifications done at low level) - * - * Remember to comment this test again on TestKernelSets.cs when you are ready to merge your modifications! + * It is impossible to make assertions here but it is useful in any case to have it runs automatically + * to catch stack overflows / corruptions when the CGS code is modified. */ namespace GraphicTest { @@ -43,8 +37,54 @@ namespace GraphicTest Console.WriteLine("Cosmos booted successfully. Let's go in Graphic Mode"); canvas = FullScreenCanvas.GetFullScreenCanvas(); + } - canvas.Clear(Color.Blue); + private void DoTest (Canvas aCanvas) + { + mDebugger.Send($"Testing Canvas with mode {aCanvas.Mode}"); + aCanvas.Clear(Color.Blue); + + /* A red Point */ + Pen pen = new Pen(Color.Red); + aCanvas.DrawPoint(pen, 69, 69); + + /* A GreenYellow horizontal line */ + pen.Color = Color.GreenYellow; + aCanvas.DrawLine(pen, 250, 100, 400, 100); + + /* An IndianRed vertical line */ + pen.Color = Color.IndianRed; + aCanvas.DrawLine(pen, 350, 150, 350, 250); + + /* A MintCream diagonal line */ + pen.Color = Color.MintCream; + aCanvas.DrawLine(pen, 250, 150, 400, 250); + + /* Rectangles of various colors */ + pen.Color = Color.PaleVioletRed; + aCanvas.DrawRectangle(pen, 350, 350, 80, 60); + + pen.Color = Color.Chartreuse; + aCanvas.DrawCircle(pen, 69, 69, 10); + + pen.Color = Color.DimGray; + aCanvas.DrawEllipse(pen, 100, 69, 10, 50); + + pen.Color = Color.MediumPurple; + aCanvas.DrawPolygon(pen, new Point(200, 250), new Point(250, 300), new Point(220, 350), new Point(210, 275)); + + /* A LimeGreen rectangle */ + pen.Color = Color.LimeGreen; + aCanvas.DrawRectangle(pen, 450, 450, 80, 60); + + /* A filled rectange */ + pen.Color = Color.Chocolate; + aCanvas.DrawFilledRectangle(pen, 200, 150, 400, 300); + + /* A Bitmpap image */ + aCanvas.DrawImage(bitmap, new Point(0, 0)); + + mDebugger.Send($"Test of Canvas with mode {aCanvas.Mode} executed successfully"); } protected override void Run() @@ -53,54 +93,13 @@ namespace GraphicTest { mDebugger.Send("Run"); - /* A red Point */ - Pen pen = new Pen(Color.Red); - canvas.DrawPoint(pen, 69, 69); + /* First test with the DefaulMode */ + DoTest(canvas); - /* A GreenYellow horizontal line */ - pen.Color = Color.GreenYellow; - canvas.DrawLine(pen, 250, 100, 400, 100); - - /* An IndianRed vertical line */ - pen.Color = Color.IndianRed; - canvas.DrawLine(pen, 350, 150, 350, 250); - - /* A MintCream diagonal line */ - pen.Color = Color.MintCream; - canvas.DrawLine(pen, 250, 150, 400, 250); - - /* A PaleVioletRed rectangle */ - pen.Color = Color.PaleVioletRed; - canvas.DrawRectangle(pen, 350, 350, 80, 60); - - pen.Color = Color.Chartreuse; - canvas.DrawCircle(pen, 69, 69, 10); - - pen.Color = Color.DimGray; - canvas.DrawEllipse(pen, 100, 69, 10, 50); - - pen.Color = Color.MediumPurple; - canvas.DrawPolygon(pen, new Point(200, 250), new Point(250, 300), new Point(220, 350), new Point(210, 275)); - - Console.ReadKey(); - - /* Let's try to change mode...*/ - canvas.Mode = new Mode(800, 600, ColorDepth.ColorDepth32); - - //If the background is not redrawn, it gets corrupted (this happens more in VmWare) - canvas.Clear(Color.Blue); - - /* A LimeGreen rectangle */ - pen.Color = Color.LimeGreen; - canvas.DrawRectangle(pen, 450, 450, 80, 60); - - /* A filled rectange */ - pen.Color = Color.Chocolate; - canvas.DrawFilledRectangle(pen, 200, 150, 400, 300); - - canvas.DrawImage(bitmap, new Point(0, 0)); - - Console.ReadKey(); + DoTest(FullScreenCanvas.GetFullScreenCanvas(new Mode(800, 600, ColorDepth.ColorDepth32))); + DoTest(FullScreenCanvas.GetFullScreenCanvas(new Mode(1024, 768, ColorDepth.ColorDepth32))); + DoTest(FullScreenCanvas.GetFullScreenCanvas(new Mode(1366, 768, ColorDepth.ColorDepth32))); + DoTest(FullScreenCanvas.GetFullScreenCanvas(new Mode(1280, 720, ColorDepth.ColorDepth32))); TestController.Completed(); } diff --git a/source/Cosmos.System2/Graphics/Canvas.cs b/source/Cosmos.System2/Graphics/Canvas.cs index 367bfab5a..96f149ec5 100644 --- a/source/Cosmos.System2/Graphics/Canvas.cs +++ b/source/Cosmos.System2/Graphics/Canvas.cs @@ -7,18 +7,16 @@ namespace Cosmos.System.Graphics { public abstract class Canvas { - protected Canvas(Mode mode) - { - //Global.mDebugger.SendInternal($"Creating a new Canvas with Mode ${mode}"); - Mode = mode; - } - - public abstract IReadOnlyList AvailableModes { get; } + /* + * IReadOnlyList is not working, the Modes inside it become corrupted and then you get Stack Overflow + */ + //public abstract IReadOnlyList AvailableModes { get; } + public abstract List AvailableModes { get; } public abstract Mode DefaultGraphicMode { get; } public abstract Mode Mode { get; set; } - + /// /// Clear all the Canvas with the Black color. /// @@ -403,12 +401,15 @@ namespace Cosmos.System.Graphics foreach (var elem in AvailableModes) { + Global.mDebugger.SendInternal($"elem is {elem} mode is {mode}"); if (elem == mode) { + Global.mDebugger.SendInternal($"Mode {mode} found"); return true; // All OK mode does exists in availableModes } } + Global.mDebugger.SendInternal($"Mode {mode} found"); return false; } @@ -419,7 +420,7 @@ namespace Cosmos.System.Graphics return; } - Global.mDebugger.SendInternal($"mode is not found! Raising exception..."); + Global.mDebugger.SendInternal($"Mode {mode} is not found! Raising exception..."); /* 'mode' was not in the 'availableModes' List ==> 'mode' in NOT Valid */ throw new ArgumentOutOfRangeException(nameof(mode), $"Mode {mode} is not supported by this Driver"); } diff --git a/source/Cosmos.System2/Graphics/FullScreenCanvas.cs b/source/Cosmos.System2/Graphics/FullScreenCanvas.cs index 7b592fc45..d2886833f 100644 --- a/source/Cosmos.System2/Graphics/FullScreenCanvas.cs +++ b/source/Cosmos.System2/Graphics/FullScreenCanvas.cs @@ -45,12 +45,15 @@ namespace Cosmos.System.Graphics public static Canvas GetFullScreenCanvas() { + Global.mDebugger.SendInternal($"GetFullScreenCanvas() with default mode"); if (MyVideoDriver == null) { + Global.mDebugger.SendInternal($"MyVideoDriver is null creating new object"); return MyVideoDriver = GetVideoDriver(); } else { + Global.mDebugger.SendInternal($"MyVideoDriver is NOT null using the old one changing mode to DefaulMode"); MyVideoDriver.Mode = MyVideoDriver.DefaultGraphicMode; return MyVideoDriver; } diff --git a/source/Cosmos.System2/Graphics/SVGAIIScreen.cs b/source/Cosmos.System2/Graphics/SVGAIIScreen.cs index 73105be4d..95567fa52 100644 --- a/source/Cosmos.System2/Graphics/SVGAIIScreen.cs +++ b/source/Cosmos.System2/Graphics/SVGAIIScreen.cs @@ -1,3 +1,4 @@ +//#define COSMOSDEBUG using System; using System.Collections.Generic; using System.Drawing; @@ -9,13 +10,13 @@ namespace Cosmos.System.Graphics { public class SVGAIIScreen : Canvas { - private static readonly Mode DefaultMode = new Mode(1024, 768, ColorDepth.ColorDepth16); + private static readonly Mode DefaultMode = new Mode(1024, 768, ColorDepth.ColorDepth32); private static readonly Debugger Debugger = new Debugger("System", "SVGAIIScreen"); private Mode _mode; - public VMWareSVGAII xSVGAIIDriver; + private readonly VMWareSVGAII xSVGAIIDriver; public SVGAIIScreen() : this(DefaultMode) @@ -23,12 +24,12 @@ namespace Cosmos.System.Graphics } public SVGAIIScreen(Mode aMode) - : base(aMode) { + Debugger.SendInternal($"Called ctor with mode {aMode}"); ThrowIfModeIsNotValid(aMode); xSVGAIIDriver = new VMWareSVGAII(); - xSVGAIIDriver.SetMode((uint)aMode.Columns, (uint)aMode.Rows, (uint)aMode.ColorDepth); + Mode = aMode; } public override Mode Mode @@ -37,6 +38,7 @@ namespace Cosmos.System.Graphics set { _mode = value; + Debugger.SendInternal($"Called Mode set property with mode {_mode}"); SetGraphicsMode(_mode); } } @@ -71,8 +73,11 @@ namespace Cosmos.System.Graphics xSVGAIIDriver.Fill((uint)x_start, (uint)y_start, (uint)width, (uint)height, (uint)pen.Color.ToArgb()); } - public override IReadOnlyList AvailableModes { get; } = new List + //public override IReadOnlyList AvailableModes { get; } = new List + 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 */ @@ -81,6 +86,7 @@ namespace Cosmos.System.Graphics 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 */ @@ -109,6 +115,7 @@ namespace Cosmos.System.Graphics 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 */ @@ -117,6 +124,7 @@ namespace Cosmos.System.Graphics 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 */ diff --git a/source/Cosmos.System2/Graphics/VBEScreen.cs b/source/Cosmos.System2/Graphics/VBEScreen.cs index eb6f4d7ca..142852f5e 100644 --- a/source/Cosmos.System2/Graphics/VBEScreen.cs +++ b/source/Cosmos.System2/Graphics/VBEScreen.cs @@ -24,13 +24,13 @@ namespace Cosmos.System.Graphics } public VBEScreen(Mode mode) - : base(mode) { Global.mDebugger.SendInternal($"Creating new VBEScreen() with mode {mode.Columns}x{mode.Rows}x{(uint)mode.ColorDepth}"); ThrowIfModeIsNotValid(mode); VBEDriver = new VBEDriver((ushort)mode.Columns, (ushort)mode.Rows, (ushort)mode.ColorDepth); + Mode = mode; } public override Mode Mode @@ -43,14 +43,15 @@ namespace Cosmos.System.Graphics } } - #region Display +#region Display /// /// All the available screen modes VBE supports, I would like to query the hardware and obtain from it the list but I have /// not yet find how to do it! For now I hardcode the most used VESA modes, VBE seems to support until HDTV resolution /// without problems that is well... excellent :-) /// - public override IReadOnlyList AvailableModes { get; } = new List + //public override IReadOnlyList AvailableModes { get; } = new List + public override List AvailableModes { get; } = new List { new Mode(320, 240, ColorDepth.ColorDepth32), new Mode(640, 480, ColorDepth.ColorDepth32), @@ -85,9 +86,9 @@ namespace Cosmos.System.Graphics //set the screen VBEDriver.VBESet(xres, yres, bpp); } - #endregion +#endregion - #region Drawing +#region Drawing public override void Clear(Color color) { @@ -211,7 +212,7 @@ namespace Cosmos.System.Graphics #endregion - #region Reading +#region Reading public override Color GetPointColor(int x, int y) { @@ -230,7 +231,7 @@ namespace Cosmos.System.Graphics return Color.FromArgb(VBEDriver.GetVRAM(offset)); } - #endregion +#endregion } }