Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump SixLabors.ImageSharp to v2.1.0 #5087

Merged
merged 6 commits into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions osu.Framework.Android/AndroidGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ protected override void SetupConfig(IDictionary<FrameworkSetting, object> defaul

protected override IWindow CreateWindow() => new AndroidGameWindow(gameView);

protected override bool LimitedMemoryEnvironment => true;

public override bool CanExit => false;

public override bool CanSuspendToBackground => true;
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework.Benchmarks/BenchmarkFontLoading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class BenchmarkFontLoading : BenchmarkTest

public override void SetUp()
{
SixLabors.ImageSharp.Configuration.Default.MemoryAllocator = ArrayPoolMemoryAllocator.CreateDefault();
SixLabors.ImageSharp.Configuration.Default.MemoryAllocator = MemoryAllocator.Default;

baseResources = new NamespacedResourceStore<byte[]>(new DllResourceStore(@"osu.Framework.dll"), @"Resources");
sharedTemp = new TemporaryNativeStorage("fontstore-test-" + Guid.NewGuid());
Expand Down Expand Up @@ -66,7 +66,7 @@ public void BenchmarkNoCache()
[Benchmark]
public void BenchmarkTimedExpiry()
{
SixLabors.ImageSharp.Configuration.Default.MemoryAllocator = ArrayPoolMemoryAllocator.CreateDefault();
SixLabors.ImageSharp.Configuration.Default.MemoryAllocator = MemoryAllocator.Default;

using (var store = new TimedExpiryGlyphStore(baseResources, font_name))
runFor(store);
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework.iOS.props
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<ItemGroup Label="Package References">
<PackageReference Include="FFmpeg.AutoGen" Version="4.3.0.1" />
<PackageReference Include="SharpFNT" Version="2.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
<PackageReference Include="ppy.osuTK.NS20" Version="1.0.187" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
Expand Down
3 changes: 2 additions & 1 deletion osu.Framework.iOS/GameAppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Threading;
using AVFoundation;
using Foundation;
using SixLabors.ImageSharp.Formats.Png;
Expand Down Expand Up @@ -54,7 +55,7 @@ private void aotImageSharp()

try
{
new PngDecoder().Decode<Rgba32>(SixLabors.ImageSharp.Configuration.Default, null);
new PngDecoder().Decode<Rgba32>(SixLabors.ImageSharp.Configuration.Default, null, CancellationToken.None);
}
catch
{
Expand Down
2 changes: 0 additions & 2 deletions osu.Framework.iOS/IOSGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ protected override void SetupConfig(IDictionary<FrameworkSetting, object> defaul

public override bool OnScreenKeyboardOverlapsGameWindow => true;

protected override bool LimitedMemoryEnvironment => true;

public override bool CanExit => false;

protected override TextInputSource CreateTextInput() => new IOSTextInput(gameView);
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework.iOS/osu.Framework.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.osuTK.iOS" Version="1.0.187" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<!-- Don't forget to update the linker attributes in AssemblyInfo.cs if you are modifying native libraries. -->
Expand Down
5 changes: 3 additions & 2 deletions osu.Framework/Extensions/ImageExtensions/ImageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System.Buffers;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;

namespace osu.Framework.Extensions.ImageExtensions
Expand Down Expand Up @@ -52,10 +53,10 @@ internal static IMemoryOwner<TPixel> CreateContiguousMemory<TPixel>(this Image<T
where TPixel : unmanaged, IPixel<TPixel>
{
var allocatedOwner = SixLabors.ImageSharp.Configuration.Default.MemoryAllocator.Allocate<TPixel>(image.Width * image.Height);
var allocatedSpan = allocatedOwner.Memory.Span;
var allocatedMemory = allocatedOwner.Memory;

for (int r = 0; r < image.Height; r++)
image.GetPixelRowSpan(r).CopyTo(allocatedSpan.Slice(r * image.Width));
image.DangerousGetPixelRowMemory(r).CopyTo(allocatedMemory.Slice(r * image.Width));

return allocatedOwner;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal ReadOnlyPixelMemory(Image<TPixel> image)
{
this.image = image;

if (image.TryGetSinglePixelSpan(out _))
if (image.DangerousTryGetSinglePixelMemory(out _))
{
owner = null;
memory = null;
Expand All @@ -46,8 +46,8 @@ public ReadOnlySpan<TPixel> Span
return Span<TPixel>.Empty;

// If the image can be returned without extra contiguous memory allocation.
if (image.TryGetSinglePixelSpan(out var pixelSpan))
return pixelSpan;
if (image.DangerousTryGetSinglePixelMemory(out var pixelMemory))
return pixelMemory.Span;

Debug.Assert(memory != null);
return memory.Value.Span;
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Extensions/ImageExtensions/ReadOnlyPixelSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public readonly ref struct ReadOnlyPixelSpan<TPixel>

internal ReadOnlyPixelSpan(Image<TPixel> image)
{
if (image.TryGetSinglePixelSpan(out var span))
if (image.DangerousTryGetSinglePixelMemory(out var memory))
{
owner = null;
Span = span;
Span = memory.Span;
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions osu.Framework/IO/Stores/GlyphStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using osu.Framework.Text;
using SharpFNT;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;

namespace osu.Framework.IO.Stores
Expand Down Expand Up @@ -153,11 +154,11 @@ protected virtual TextureUpload LoadCharacter(Character character)

for (int y = 0; y < character.Height; y++)
{
var pixelRowSpan = image.GetPixelRowSpan(y);
var pixelRowMemory = image.DangerousGetPixelRowMemory(y);
int readOffset = (character.Y + y) * page.Width + character.X;

for (int x = 0; x < character.Width; x++)
pixelRowSpan[x] = x < readableWidth && y < readableHeight ? source[readOffset + x] : new Rgba32(255, 255, 255, 0);
pixelRowMemory.Span[x] = x < readableWidth && y < readableHeight ? source[readOffset + x] : new Rgba32(255, 255, 255, 0);
}

return new TextureUpload(image);
Expand Down
5 changes: 3 additions & 2 deletions osu.Framework/IO/Stores/RawCachingGlyphStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using osu.Framework.Platform;
using SharpFNT;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;

namespace osu.Framework.IO.Stores
Expand Down Expand Up @@ -123,11 +124,11 @@ private TextureUpload createTextureUpload(Character character, PageInfo page)

for (int y = 0; y < character.Height; y++)
{
var pixelRowSpan = image.GetPixelRowSpan(y);
var pixelRowMemory = image.DangerousGetPixelRowMemory(y);
int readOffset = y * pageWidth + character.X;

for (int x = 0; x < character.Width; x++)
pixelRowSpan[x] = new Rgba32(255, 255, 255, x < readableWidth && y < readableHeight ? readBuffer[readOffset + x] : (byte)0);
pixelRowMemory.Span[x] = new Rgba32(255, 255, 255, x < readableWidth && y < readableHeight ? readBuffer[readOffset + x] : (byte)0);
}

return new TextureUpload(image);
Expand Down
12 changes: 0 additions & 12 deletions osu.Framework/Platform/GameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
using osu.Framework.Graphics.Video;
using osu.Framework.IO.Serialization;
using osu.Framework.IO.Stores;
using SixLabors.ImageSharp.Memory;
using Image = SixLabors.ImageSharp.Image;
using PixelFormat = osuTK.Graphics.ES30.PixelFormat;
using Size = System.Drawing.Size;
Expand Down Expand Up @@ -115,11 +114,6 @@ public abstract class GameHost : IIpcHost, IDisposable
/// </remarks>
public virtual bool CanSuspendToBackground => false;

/// <summary>
/// Whether memory constraints should be considered before performance concerns.
/// </summary>
protected virtual bool LimitedMemoryEnvironment => false;

protected IpcMessage OnMessageReceived(IpcMessage message) => MessageReceived?.Invoke(message);

public virtual Task SendMessageAsync(IpcMessage message) => throw new NotSupportedException("This platform does not implement IPC.");
Expand Down Expand Up @@ -665,12 +659,6 @@ public void Run(Game game)

GCSettings.LatencyMode = GCLatencyMode.SustainedLowLatency;

if (LimitedMemoryEnvironment)
{
// recommended middle-ground https://github.com/SixLabors/docs/blob/master/articles/ImageSharp/MemoryManagement.md#working-in-memory-constrained-environments
SixLabors.ImageSharp.Configuration.Default.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithModeratePooling();
}

if (ExecutionState != ExecutionState.Idle)
throw new InvalidOperationException("A game that has already been run cannot be restarted.");

Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/osu.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageReference Include="NuGet.ProjectModel" Version="5.11.0" />
<PackageReference Include="SharpFNT" Version="2.0.0" />
<!-- Preview version of ImageSharp causes NU5104. -->
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="ManagedBass" Version="3.1.0" />
<PackageReference Include="ManagedBass.Fx" Version="3.1.0" />
Expand Down