Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/auto-load-e…
Browse files Browse the repository at this point in the history
…xtra-files
  • Loading branch information
J-Swift committed Aug 31, 2024
2 parents b3f3b19 + 2c5c039 commit 401e60e
Show file tree
Hide file tree
Showing 25 changed files with 514 additions and 343 deletions.
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
<PackageVersion Include="Silk.NET.Vulkan" Version="2.16.0" />
<PackageVersion Include="Silk.NET.Vulkan.Extensions.EXT" Version="2.16.0" />
<PackageVersion Include="Silk.NET.Vulkan.Extensions.KHR" Version="2.16.0" />
<PackageVersion Include="SixLabors.ImageSharp" Version="2.1.9" />
<PackageVersion Include="SixLabors.ImageSharp.Drawing" Version="1.0.0" />
<PackageVersion Include="SkiaSharp" Version="2.88.7" />
<PackageVersion Include="SkiaSharp.NativeAssets.Linux" Version="2.88.7" />
<PackageVersion Include="SPB" Version="0.0.4-build32" />
<PackageVersion Include="System.IO.Hashing" Version="8.0.0" />
<PackageVersion Include="System.Management" Version="8.0.0" />
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" />
</ItemGroup>
</Project>
</Project>
6 changes: 6 additions & 0 deletions Ryujinx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.Horizon", "src\Ryuj
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.Horizon.Kernel.Generators", "src\Ryujinx.Horizon.Kernel.Generators\Ryujinx.Horizon.Kernel.Generators.csproj", "{7F55A45D-4E1D-4A36-ADD3-87F29A285AA2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.HLE.Generators", "src\Ryujinx.HLE.Generators\Ryujinx.HLE.Generators.csproj", "{B575BCDE-2FD8-4A5D-8756-31CDD7FE81F0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -249,6 +251,10 @@ Global
{7F55A45D-4E1D-4A36-ADD3-87F29A285AA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F55A45D-4E1D-4A36-ADD3-87F29A285AA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F55A45D-4E1D-4A36-ADD3-87F29A285AA2}.Release|Any CPU.Build.0 = Release|Any CPU
{B575BCDE-2FD8-4A5D-8756-31CDD7FE81F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B575BCDE-2FD8-4A5D-8756-31CDD7FE81F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B575BCDE-2FD8-4A5D-8756-31CDD7FE81F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B575BCDE-2FD8-4A5D-8756-31CDD7FE81F0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 4 additions & 1 deletion src/ARMeilleure/Translation/TranslatorQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ public bool TryDequeue(out RejitRequest result)
return true;
}

Monitor.Wait(Sync);
if (!_disposed)
{
Monitor.Wait(Sync);
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/Ryujinx.Graphics.Device/DeviceState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public DeviceState(IReadOnlyDictionary<string, RwCallback> callbacks = null, Act
{
var field = fields[fieldIndex];

int sizeOfField = SizeCalculator.SizeOf(field.FieldType);
var currentFieldOffset = (int)Marshal.OffsetOf<TState>(field.Name);
var nextFieldOffset = fieldIndex + 1 == fields.Length ? Unsafe.SizeOf<TState>() : (int)Marshal.OffsetOf<TState>(fields[fieldIndex + 1].Name);

int sizeOfField = nextFieldOffset - currentFieldOffset;

for (int i = 0; i < ((sizeOfField + 3) & ~3); i += 4)
{
Expand Down
63 changes: 0 additions & 63 deletions src/Ryujinx.Graphics.Device/SizeCalculator.cs

This file was deleted.

5 changes: 4 additions & 1 deletion src/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdateTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ public StateUpdateTracker(StateUpdateCallbackEntry[] entries)
{
var field = fields[fieldIndex];

int sizeOfField = SizeCalculator.SizeOf(field.FieldType);
var currentFieldOffset = (int)Marshal.OffsetOf<TState>(field.Name);
var nextFieldOffset = fieldIndex + 1 == fields.Length ? Unsafe.SizeOf<TState>() : (int)Marshal.OffsetOf<TState>(fields[fieldIndex + 1].Name);

int sizeOfField = nextFieldOffset - currentFieldOffset;

if (fieldToDelegate.TryGetValue(field.Name, out int entryIndex))
{
Expand Down
7 changes: 0 additions & 7 deletions src/Ryujinx.Gtk3/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Ryujinx.UI.Common.Helper;
using Ryujinx.UI.Common.SystemInfo;
using Ryujinx.UI.Widgets;
using SixLabors.ImageSharp.Formats.Jpeg;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -162,12 +161,6 @@ static void SetEnvironmentVariableNoCaching(string key, string value)
});
};

// Sets ImageSharp Jpeg Encoder Quality.
SixLabors.ImageSharp.Configuration.Default.ImageFormatsManager.SetEncoder(JpegFormat.Instance, new JpegEncoder()
{
Quality = 100,
});

string localConfigurationPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ReleaseInformation.ConfigName);
string appDataConfigurationPath = Path.Combine(AppDataManager.BaseDirPath, ReleaseInformation.ConfigName);

Expand Down
1 change: 0 additions & 1 deletion src/Ryujinx.Gtk3/Ryujinx.Gtk3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<PackageReference Include="OpenTK.Graphics" />
<PackageReference Include="SPB" />
<PackageReference Include="SharpZipLib" />
<PackageReference Include="SixLabors.ImageSharp" />
</ItemGroup>

<ItemGroup>
Expand Down
39 changes: 22 additions & 17 deletions src/Ryujinx.Gtk3/UI/RendererWidgetBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@
using Ryujinx.UI.Common.Configuration;
using Ryujinx.UI.Common.Helper;
using Ryujinx.UI.Widgets;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SkiaSharp;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Image = SixLabors.ImageSharp.Image;
using Key = Ryujinx.Input.Key;
using ScalingFilter = Ryujinx.Graphics.GAL.ScalingFilter;
using Switch = Ryujinx.HLE.Switch;
Expand Down Expand Up @@ -404,23 +401,31 @@ private unsafe void Renderer_ScreenCaptured(object sender, ScreenCaptureImageInf
return;
}

Image image = e.IsBgra ? Image.LoadPixelData<Bgra32>(e.Data, e.Width, e.Height)
: Image.LoadPixelData<Rgba32>(e.Data, e.Width, e.Height);
var colorType = e.IsBgra ? SKColorType.Bgra8888 : SKColorType.Rgba8888;
using var image = new SKBitmap(new SKImageInfo(e.Width, e.Height, colorType, SKAlphaType.Premul));

if (e.FlipX)
{
image.Mutate(x => x.Flip(FlipMode.Horizontal));
}
Marshal.Copy(e.Data, 0, image.GetPixels(), e.Data.Length);
using var surface = SKSurface.Create(image.Info);
var canvas = surface.Canvas;

if (e.FlipY)
if (e.FlipX || e.FlipY)
{
image.Mutate(x => x.Flip(FlipMode.Vertical));
canvas.Clear(SKColors.Transparent);

float scaleX = e.FlipX ? -1 : 1;
float scaleY = e.FlipY ? -1 : 1;

var matrix = SKMatrix.CreateScale(scaleX, scaleY, image.Width / 2f, image.Height / 2f);

canvas.SetMatrix(matrix);
}
canvas.DrawBitmap(image, new SKPoint());

image.SaveAsPng(path, new PngEncoder()
{
ColorType = PngColorType.Rgb,
});
surface.Flush();
using var snapshot = surface.Snapshot();
using var encoded = snapshot.Encode(SKEncodedImageFormat.Png, 80);
using var file = File.OpenWrite(path);
encoded.SaveTo(file);

image.Dispose();

Expand Down
29 changes: 18 additions & 11 deletions src/Ryujinx.Gtk3/UI/Windows/AvatarWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
using Ryujinx.Common.Memory;
using Ryujinx.HLE.FileSystem;
using Ryujinx.UI.Common.Configuration;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SkiaSharp;
using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Image = SixLabors.ImageSharp.Image;
using System.Runtime.InteropServices;

namespace Ryujinx.UI.Windows
{
Expand Down Expand Up @@ -144,9 +141,11 @@ public static void PreloadAvatars(ContentManager contentManager, VirtualFileSyst

stream.Position = 0;

Image avatarImage = Image.LoadPixelData<Rgba32>(DecompressYaz0(stream), 256, 256);
using var avatarImage = new SKBitmap(new SKImageInfo(256, 256, SKColorType.Rgba8888));
var data = DecompressYaz0(stream);
Marshal.Copy(data, 0, avatarImage.GetPixels(), data.Length);

avatarImage.SaveAsPng(streamPng);
avatarImage.Encode(streamPng, SKEncodedImageFormat.Png, 80);

_avatarDict.Add(item.FullPath, streamPng.ToArray());
}
Expand All @@ -170,15 +169,23 @@ private byte[] ProcessImage(byte[] data)
{
using MemoryStream streamJpg = MemoryStreamManager.Shared.GetStream();

Image avatarImage = Image.Load(data, new PngDecoder());
using var avatarImage = SKBitmap.Decode(data);
using var surface = SKSurface.Create(avatarImage.Info);

avatarImage.Mutate(x => x.BackgroundColor(new Rgba32(
var background = new SKColor(
(byte)(_backgroundColor.Red * 255),
(byte)(_backgroundColor.Green * 255),
(byte)(_backgroundColor.Blue * 255),
(byte)(_backgroundColor.Alpha * 255)
)));
avatarImage.SaveAsJpeg(streamJpg);
);
var canvas = surface.Canvas;
canvas.Clear(background);
canvas.DrawBitmap(avatarImage, new SKPoint());

surface.Flush();
using var snapshot = surface.Snapshot();
using var encoded = snapshot.Encode(SKEncodedImageFormat.Jpeg, 80);
encoded.SaveTo(streamJpg);

return streamJpg.ToArray();
}
Expand Down
10 changes: 4 additions & 6 deletions src/Ryujinx.Gtk3/UI/Windows/UserProfilesManagerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
using Ryujinx.HLE.HOS.Services.Account.Acc;
using Ryujinx.UI.Common.Configuration;
using Ryujinx.UI.Widgets;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Image = SixLabors.ImageSharp.Image;

namespace Ryujinx.UI.Windows
{
Expand Down Expand Up @@ -177,13 +175,13 @@ private void EditProfileNameButton_Pressed(object sender, EventArgs e)

private void ProcessProfileImage(byte[] buffer)
{
using Image image = Image.Load(buffer);
using var image = SKBitmap.Decode(buffer);

image.Mutate(x => x.Resize(256, 256));
image.Resize(new SKImageInfo(256, 256), SKFilterQuality.High);

using MemoryStream streamJpg = MemoryStreamManager.Shared.GetStream();

image.SaveAsJpeg(streamJpg);
image.Encode(streamJpg, SKEncodedImageFormat.Jpeg, 80);

_bufferImageProfile = streamJpg.ToArray();
}
Expand Down
63 changes: 63 additions & 0 deletions src/Ryujinx.HLE.Generators/CodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Text;

namespace Ryujinx.HLE.Generators
{
class CodeGenerator
{
private const int IndentLength = 4;

private readonly StringBuilder _sb;
private int _currentIndentCount;

public CodeGenerator()
{
_sb = new StringBuilder();
}

public void EnterScope(string header = null)
{
if (header != null)
{
AppendLine(header);
}

AppendLine("{");
IncreaseIndentation();
}

public void LeaveScope(string suffix = "")
{
DecreaseIndentation();
AppendLine($"}}{suffix}");
}

public void IncreaseIndentation()
{
_currentIndentCount++;
}

public void DecreaseIndentation()
{
if (_currentIndentCount - 1 >= 0)
{
_currentIndentCount--;
}
}

public void AppendLine()
{
_sb.AppendLine();
}

public void AppendLine(string text)
{
_sb.Append(' ', IndentLength * _currentIndentCount);
_sb.AppendLine(text);
}

public override string ToString()
{
return _sb.ToString();
}
}
}
Loading

0 comments on commit 401e60e

Please sign in to comment.