Skip to content

Commit

Permalink
Merge pull request CosmosOS#2709 from CosmosOS/feature/CGS-optimisation
Browse files Browse the repository at this point in the history
Little CGS optimisations
  • Loading branch information
valentinbreiz authored Jun 18, 2023
2 parents f497fd6 + fafdb68 commit a95f561
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
15 changes: 10 additions & 5 deletions source/Cosmos.System2/Graphics/Canvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,13 @@ public void DrawImageAlpha(Image image, int x, int y)
/// <param name="y">The origin Y coordinate.</param>
public virtual void DrawString(string str, Font font, Color color, int x, int y)
{
for (int i = 0; i < str.Length; i++)
var len = str.Length;
var width = font.Width;

for (int i = 0; i < len; i++)
{
DrawChar(str[i], font, color, x, y);
x += font.Width;
x += width;
}
}

Expand All @@ -642,15 +645,17 @@ public virtual void DrawString(string str, Font font, Color color, int x, int y)
/// <inheritdoc cref="DrawString(string, Font, Color, int, int)"/>
public virtual void DrawChar(char c, Font font, Color color, int x, int y)
{
var width = font.Width;
var height = font.Height;
int p = font.Height * (byte)c;

for (int cy = 0; cy < font.Height; cy++)
for (int cy = 0; cy < height; cy++)
{
for (byte cx = 0; cx < font.Width; cx++)
for (byte cx = 0; cx < width; cx++)
{
if (font.ConvertByteToBitAddress(font.Data[p + cy], cx + 1))
{
DrawPoint(color, (ushort)(x + (font.Width - cx)), (ushort)(y + cy));
DrawPoint(color, (ushort)(x + (width - cx)), (ushort)(y + cy));
}
}
}
Expand Down
17 changes: 11 additions & 6 deletions source/Cosmos.System2/Graphics/SVGAIICanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,24 +316,29 @@ public override void Display()

public override void DrawString(string str, Font font, Color color, int x, int y)
{
for (int i = 0; i < str.Length; i++)
var len = str.Length;
var width = font.Width;

for (int i = 0; i < len; i++)
{
DrawChar(str[i], font, color, x, y);
x += font.Width;
x += width;
}
}

public override void DrawChar(char c, Font font, Color color, int x, int y)
{
int p = font.Height * (byte)c;
var height = font.Height;
var width = font.Width;
int p = height * (byte)c;

for (int cy = 0; cy < font.Height; cy++)
for (int cy = 0; cy < height; cy++)
{
for (byte cx = 0; cx < font.Width; cx++)
for (byte cx = 0; cx < width; cx++)
{
if (font.ConvertByteToBitAddress(font.Data[p + cy], cx + 1))
{
DrawPoint(color, (ushort)(x + (font.Width - cx)), (ushort)(y + cy));
DrawPoint(color, (ushort)(x + (width - cx)), (ushort)(y + cy));
}
}
}
Expand Down

0 comments on commit a95f561

Please sign in to comment.