Commit aa3ce07 1 parent b512df4 commit aa3ce07 Copy full SHA for aa3ce07
File tree 2 files changed +42
-0
lines changed
osu.Framework/Platform/MacOS
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 7
7
using System . Collections . Generic ;
8
8
using System . IO ;
9
9
using System . Linq ;
10
+ using osu . Framework . Graphics . Textures ;
10
11
using osu . Framework . Input ;
11
12
using osu . Framework . Input . Bindings ;
12
13
using osu . Framework . Input . Handlers ;
13
14
using osu . Framework . Input . Handlers . Mouse ;
15
+ using osu . Framework . IO . Stores ;
14
16
using osu . Framework . Logging ;
15
17
using osu . Framework . Platform . MacOS . Native ;
16
18
@@ -44,6 +46,9 @@ public override IEnumerable<string> UserStoragePaths
44
46
45
47
protected override ReadableKeyCombinationProvider CreateReadableKeyCombinationProvider ( ) => new MacOSReadableKeyCombinationProvider ( ) ;
46
48
49
+ public override IResourceStore < TextureUpload > CreateTextureLoaderStore ( IResourceStore < byte [ ] > underlyingStore )
50
+ => new MacOSTextureLoaderStore ( underlyingStore ) ;
51
+
47
52
protected override void Swap ( )
48
53
{
49
54
base . Swap ( ) ;
Original file line number Diff line number Diff line change
1
+ // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2
+ // See the LICENCE file in the repository root for full licence text.
3
+
4
+ using System ;
5
+ using System . IO ;
6
+ using osu . Framework . IO . Stores ;
7
+ using osu . Framework . Platform . Apple ;
8
+ using osu . Framework . Platform . Apple . Native ;
9
+ using osu . Framework . Platform . MacOS . Native ;
10
+ using SixLabors . ImageSharp ;
11
+
12
+ namespace osu . Framework . Platform . MacOS
13
+ {
14
+ internal class MacOSTextureLoaderStore : AppleTextureLoaderStore
15
+ {
16
+ public MacOSTextureLoaderStore ( IResourceStore < byte [ ] > store )
17
+ : base ( store )
18
+ {
19
+ }
20
+
21
+ protected override unsafe Image < TPixel > ImageFromStream < TPixel > ( Stream stream )
22
+ {
23
+ int length = ( int ) ( stream . Length - stream . Position ) ;
24
+ using var nativeData = NSMutableData . FromLength ( length ) ;
25
+
26
+ var bytesSpan = new Span < byte > ( nativeData . MutableBytes , length ) ;
27
+ stream . ReadExactly ( bytesSpan ) ;
28
+
29
+ using var nsImage = NSImage . LoadFromData ( nativeData ) ;
30
+ if ( nsImage . Handle == IntPtr . Zero )
31
+ throw new ArgumentException ( $ "{ nameof ( Image ) } could not be created from { nameof ( stream ) } .") ;
32
+
33
+ var cgImage = nsImage . CGImage ;
34
+ return ImageFromCGImage < TPixel > ( cgImage ) ;
35
+ }
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments