Skip to content

Commit

Permalink
Use MemoryOperation.Copy for SVGAII Canvas DrawImage
Browse files Browse the repository at this point in the history
Make VideoMemory from SVGAII Canvas public
Add MemoryOperation Copy overload
  • Loading branch information
quajak committed Oct 20, 2021
1 parent 8c80fb6 commit d5903c3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Tests/Cosmos.TestRunner.Full/DefaultEngineConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public virtual IEnumerable<RunTargetEnum> RunTargets
{
get
{
yield return RunTargetEnum.Bochs;
//yield return RunTargetEnum.VMware;
//yield return RunTargetEnum.Bochs;
yield return RunTargetEnum.VMware;
//yield return RunTargetEnum.HyperV;
//yield return RunTargetEnum.Qemu;
}
Expand Down
30 changes: 15 additions & 15 deletions Tests/Cosmos.TestRunner.Full/TestKernelSets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ public static IEnumerable<Type> GetKernelTypesToRun()
// Stable kernel types: the ones that are stable and will run in AppVeyor
public static IEnumerable<Type> GetStableKernelTypes()
{
yield return typeof(BoxingTests.Kernel);
yield return typeof(Compiler.Tests.TypeSystem.Kernel);
//yield return typeof(SimpleStructsandArraysTest.Kernel);
yield return typeof(Compiler.Tests.Bcl.Kernel);
yield return typeof(Compiler.Tests.Bcl.System.Kernel);
yield return typeof(Compiler.Tests.Encryption.Kernel);
yield return typeof(Compiler.Tests.Exceptions.Kernel);
yield return typeof(Compiler.Tests.MethodTests.Kernel);
yield return typeof(Compiler.Tests.SingleEchoTest.Kernel);
yield return typeof(Kernel.Tests.Fat.Kernel);
yield return typeof(Kernel.Tests.IO.Kernel);
yield return typeof(Kernel.Tests.DiskManager.Kernel);
//yield return typeof(BoxingTests.Kernel);
//yield return typeof(Cosmos.Compiler.Tests.TypeSystem.Kernel);
//yield return typeof(Cosmos.Compiler.Tests.Bcl.Kernel);
//yield return typeof(Cosmos.Compiler.Tests.Bcl.System.Kernel);
////yield return typeof(Cosmos.Compiler.Tests.Encryption.Kernel);
//yield return typeof(Cosmos.Compiler.Tests.Exceptions.Kernel);
//yield return typeof(Cosmos.Compiler.Tests.MethodTests.Kernel);
//yield return typeof(Cosmos.Compiler.Tests.SingleEchoTest.Kernel);
//yield return typeof(Cosmos.Kernel.Tests.Fat.Kernel);
//yield return typeof(Cosmos.Kernel.Tests.IO.Kernel);
//yield return typeof(SimpleStructsAndArraysTest.Kernel);
//yield return typeof(Cosmos.Kernel.Tests.DiskManager.Kernel);

//yield return typeof(KernelGen3.Boot);

yield return typeof(GraphicTest.Kernel);
yield return typeof(NetworkTest.Kernel);
//yield return typeof(NetworkTest.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 */
yield return typeof(MemoryOperationsTest.Kernel);
yield return typeof(ProcessorTests.Kernel);
//yield return typeof(MemoryOperationsTest.Kernel);
//yield return typeof(ProcessorTests.Kernel);
}
}
}
29 changes: 22 additions & 7 deletions source/Cosmos.Core/MemoryOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ public unsafe class MemoryOperations
/// <summary>
/// Fill memory block. Plugged.
/// </summary>
/// <param name="dest">A destination.</param>
/// <param name="aDest">A destination.</param>
/// <param name="aValue">A data value.</param>
/// <param name="size">Number of bytes to fill</param>
public static unsafe void Fill(byte* dest, int aValue, int size)
/// <param name="aSize">A data size.</param>
public static unsafe void Fill(byte* aDest, int aValue, int aSize)
{
// Plugged but we use this for unit tests
var bytes = BitConverter.GetBytes(aValue);
for (int i = 0; i < size; i++)
for (int i = 0; i < aSize; i++)
{
dest[i] = bytes[i % 4];
aDest[i] = bytes[i % 4];
}
}

Expand All @@ -37,7 +37,7 @@ public static unsafe void Fill(uint* dest, uint value, int size)
{
Fill((byte*)dest, (int)value, size * 4);
}

/// <summary>
/// Fill destination region with value.
/// </summary>
Expand Down Expand Up @@ -353,6 +353,21 @@ public static unsafe void Copy(byte[] dest, byte[] src)
}
}

#endregion Copy
/// <summary>
/// Copy source to destination.
/// </summary>
/// <param name="dest">Destination.</param>
/// <param name="src">Source.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void Copy(byte[] aDest, int aDestOffset, byte[] aSrc, int aSrcOffset, int aCount)
{
fixed (byte* destPtr = &aDest[aDestOffset])
fixed (byte* srcPtr = &aSrc[aSrcOffset])
{
Copy(destPtr, srcPtr, aCount);
}
}

#endregion Copy
}
}
8 changes: 4 additions & 4 deletions source/Cosmos.HAL2/Drivers/PCI/Video/VMWareSVGAII.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ private enum Capability
/// <summary>
/// Video memory block.
/// </summary>
private MemoryBlock Video_Memory;
public MemoryBlock VideoMemory;
/// <summary>
/// FIFO memory block.
/// </summary>
Expand Down Expand Up @@ -491,7 +491,7 @@ public VMWareSVGAII()
if (ReadRegister(Register.ID) != (uint)ID.V2)
return;

Video_Memory = new MemoryBlock(ReadRegister(Register.FrameBufferStart), ReadRegister(Register.VRamSize));
VideoMemory = new MemoryBlock(ReadRegister(Register.FrameBufferStart), ReadRegister(Register.VRamSize));
capabilities = ReadRegister(Register.Capabilities);
InitializeFIFO();
}
Expand Down Expand Up @@ -625,7 +625,7 @@ public void Update(uint x, uint y, uint width, uint height)
/// <exception cref="Exception">Thrown on memory access violation.</exception>
public void SetPixel(uint x, uint y,uint color)
{
Video_Memory[((y * width + x) * depth)] = color;
VideoMemory[((y * width + x) * depth)] = color;
}

/// <summary>
Expand All @@ -637,7 +637,7 @@ public void SetPixel(uint x, uint y,uint color)
/// <exception cref="Exception">Thrown on memory access violation.</exception>
public uint GetPixel(uint x, uint y)
{
return Video_Memory[((y * width + x) * depth)];
return VideoMemory[((y * width + x) * depth)];
}

/// <summary>
Expand Down
10 changes: 9 additions & 1 deletion source/Cosmos.System2/Graphics/SVGAIICanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;

using Cosmos.Core;
using Cosmos.Debug.Kernel;
using Cosmos.HAL.Drivers.PCI.Video;

Expand Down Expand Up @@ -394,5 +394,13 @@ public override void Display()
{

}

public override void DrawImage(Image aImage, int aX, int aY)
{
for (int y = 0; y < aImage.Height; y++)
{
_xSVGADriver.VideoMemory.Copy((int)(aX + (aY + y) * aImage.Width), aImage.rawData, (int)(y * aImage.Width), (int)aImage.Width);
}
}
}
}

0 comments on commit d5903c3

Please sign in to comment.