File tree 13 files changed +72
-51
lines changed
osu.Framework.iOS/Graphics/Textures
13 files changed +72
-51
lines changed Original file line number Diff line number Diff line change @@ -20,18 +20,21 @@ public IOSTextureLoaderStore(IResourceStore<byte[]> store)
20
20
21
21
protected override unsafe Image < TPixel > ImageFromStream < TPixel > ( Stream stream )
22
22
{
23
- int length = ( int ) ( stream . Length - stream . Position ) ;
24
- using var nativeData = NSMutableData . FromLength ( length ) ;
23
+ using ( new NSAutoreleasePool ( ) )
24
+ {
25
+ int length = ( int ) ( stream . Length - stream . Position ) ;
26
+ var nativeData = NSMutableData . FromLength ( length ) ;
25
27
26
- var bytesSpan = new Span < byte > ( nativeData . MutableBytes . ToPointer ( ) , length ) ;
27
- stream . ReadExactly ( bytesSpan ) ;
28
+ var bytesSpan = new Span < byte > ( nativeData . MutableBytes . ToPointer ( ) , length ) ;
29
+ stream . ReadExactly ( bytesSpan ) ;
28
30
29
- using var uiImage = UIImage . LoadFromData ( nativeData ) ;
30
- if ( uiImage == null )
31
- throw new ArgumentException ( $ "{ nameof ( Image ) } could not be created from { nameof ( stream ) } .") ;
31
+ using var uiImage = UIImage . LoadFromData ( nativeData ) ;
32
+ if ( uiImage == null )
33
+ throw new ArgumentException ( $ "{ nameof ( Image ) } could not be created from { nameof ( stream ) } .") ;
32
34
33
- var cgImage = new Platform . Apple . Native . CGImage ( uiImage . CGImage ! . Handle ) ;
34
- return ImageFromCGImage < TPixel > ( cgImage ) ;
35
+ var cgImage = new Platform . Apple . Native . CGImage ( uiImage . CGImage ! . Handle ) ;
36
+ return ImageFromCGImage < TPixel > ( cgImage ) ;
37
+ }
35
38
}
36
39
}
37
40
}
Original file line number Diff line number Diff line change 3
3
4
4
using System ;
5
5
using System . Runtime . InteropServices ;
6
- using osu . Framework . Platform . MacOS . Native ;
7
6
8
7
namespace osu . Framework . Platform . Apple . Native
9
8
{
Original file line number Diff line number Diff line change 2
2
// See the LICENCE file in the repository root for full licence text.
3
3
4
4
using System ;
5
- using osu . Framework . Platform . MacOS . Native ;
6
5
7
6
namespace osu . Framework . Platform . Apple . Native
8
7
{
Original file line number Diff line number Diff line change
1
+ // Copyright (c) ppy Pty Ltd <[email protected] >. Licensed under the MIT Licence.
2
+ // See the LICENCE file in the repository root for full licence text.
3
+
4
+ using System ;
5
+
6
+ namespace osu . Framework . Platform . Apple . Native
7
+ {
8
+ internal readonly struct NSAutoreleasePool : IDisposable
9
+ {
10
+ internal IntPtr Handle { get ; }
11
+
12
+ internal NSAutoreleasePool ( IntPtr handle )
13
+ {
14
+ Handle = handle ;
15
+ }
16
+
17
+ private static readonly IntPtr class_pointer = Class . Get ( "NSAutoreleasePool" ) ;
18
+ private static readonly IntPtr sel_alloc = Selector . Get ( "alloc" ) ;
19
+ private static readonly IntPtr sel_init = Selector . Get ( "init" ) ;
20
+ private static readonly IntPtr sel_drain = Selector . Get ( "drain" ) ;
21
+
22
+ public static NSAutoreleasePool Init ( )
23
+ {
24
+ var pool = alloc ( ) ;
25
+ Interop . SendIntPtr ( pool . Handle , sel_init ) ;
26
+ return pool ;
27
+ }
28
+
29
+ private static NSAutoreleasePool alloc ( ) => new NSAutoreleasePool ( Interop . SendIntPtr ( class_pointer , sel_alloc ) ) ;
30
+
31
+ public void Dispose ( )
32
+ {
33
+ if ( Handle != IntPtr . Zero )
34
+ Interop . SendIntPtr ( Handle , sel_drain ) ;
35
+ }
36
+ }
37
+ }
Original file line number Diff line number Diff line change 3
3
4
4
using System ;
5
5
using System . Runtime . InteropServices ;
6
- using osu . Framework . Platform . MacOS . Native ;
7
6
8
7
namespace osu . Framework . Platform . Apple . Native
9
8
{
10
- internal readonly struct NSData : IDisposable
9
+ internal readonly struct NSData
11
10
{
12
11
internal IntPtr Handle { get ; }
13
12
14
13
private static readonly IntPtr class_pointer = Class . Get ( "NSData" ) ;
15
- private static readonly IntPtr sel_release = Selector . Get ( "release" ) ;
16
14
private static readonly IntPtr sel_data_with_bytes = Selector . Get ( "dataWithBytes:length:" ) ;
17
15
private static readonly IntPtr sel_bytes = Selector . Get ( "bytes" ) ;
18
16
private static readonly IntPtr sel_length = Selector . Get ( "length" ) ;
@@ -34,14 +32,6 @@ internal byte[] ToBytes()
34
32
return bytes ;
35
33
}
36
34
37
- internal void Release ( ) => Interop . SendVoid ( Handle , sel_release ) ;
38
-
39
- public void Dispose ( )
40
- {
41
- if ( Handle != IntPtr . Zero )
42
- Release ( ) ;
43
- }
44
-
45
35
internal static unsafe NSData FromBytes ( ReadOnlySpan < byte > bytes )
46
36
{
47
37
fixed ( byte * ptr = bytes )
Original file line number Diff line number Diff line change 2
2
// See the LICENCE file in the repository root for full licence text.
3
3
4
4
using System ;
5
- using osu . Framework . Platform . MacOS . Native ;
6
5
7
6
namespace osu . Framework . Platform . Apple . Native
8
7
{
9
- internal readonly struct NSMutableData : IDisposable
8
+ internal readonly struct NSMutableData
10
9
{
11
10
internal IntPtr Handle { get ; }
12
11
13
12
private static readonly IntPtr class_pointer = Class . Get ( "NSMutableData" ) ;
14
- private static readonly IntPtr sel_release = Selector . Get ( "release" ) ;
15
13
private static readonly IntPtr sel_data_with_length = Selector . Get ( "dataWithLength:" ) ;
16
14
private static readonly IntPtr sel_mutable_bytes = Selector . Get ( "mutableBytes" ) ;
17
15
@@ -22,14 +20,6 @@ internal NSMutableData(IntPtr handle)
22
20
23
21
internal unsafe byte * MutableBytes => ( byte * ) Interop . SendIntPtr ( Handle , sel_mutable_bytes ) ;
24
22
25
- internal void Release ( ) => Interop . SendVoid ( Handle , sel_release ) ;
26
-
27
- public void Dispose ( )
28
- {
29
- if ( Handle != IntPtr . Zero )
30
- Release ( ) ;
31
- }
32
-
33
23
internal static NSMutableData FromLength ( int length )
34
24
{
35
25
IntPtr handle = Interop . SendIntPtr ( class_pointer , sel_data_with_length , length ) ;
Original file line number Diff line number Diff line change 2
2
// See the LICENCE file in the repository root for full licence text.
3
3
4
4
using System ;
5
- using osu . Framework . Platform . MacOS . Native ;
6
5
7
6
namespace osu . Framework . Platform . Apple . Native
8
7
{
Original file line number Diff line number Diff line change 3
3
4
4
using System ;
5
5
using System . Runtime . InteropServices ;
6
- using osu . Framework . Platform . MacOS . Native ;
7
6
8
7
namespace osu . Framework . Platform . Apple . Native
9
8
{
Original file line number Diff line number Diff line change 3
3
4
4
using System ;
5
5
using System . Runtime . InteropServices ;
6
- using osu . Framework . Platform . Apple . Native ;
7
6
8
- namespace osu . Framework . Platform . MacOS . Native
7
+ namespace osu . Framework . Platform . Apple . Native
9
8
{
10
9
internal static partial class Selector
11
10
{
Original file line number Diff line number Diff line change @@ -35,9 +35,12 @@ public override bool SetImage(Image image)
35
35
using var stream = new MemoryStream ( ) ;
36
36
image . SaveAsTiff ( stream ) ;
37
37
38
- using var nsData = NSData . FromBytes ( stream . ToArray ( ) ) ;
39
- using var nsImage = NSImage . LoadFromData ( nsData ) ;
40
- return setToPasteboard ( nsImage . Handle ) ;
38
+ using ( NSAutoreleasePool . Init ( ) )
39
+ {
40
+ var nsData = NSData . FromBytes ( stream . ToArray ( ) ) ;
41
+ using var nsImage = NSImage . LoadFromData ( nsData ) ;
42
+ return setToPasteboard ( nsImage . Handle ) ;
43
+ }
41
44
}
42
45
43
46
private IntPtr getFromPasteboard ( IntPtr @class )
Original file line number Diff line number Diff line change @@ -20,18 +20,21 @@ public MacOSTextureLoaderStore(IResourceStore<byte[]> store)
20
20
21
21
protected override unsafe Image < TPixel > ImageFromStream < TPixel > ( Stream stream )
22
22
{
23
- int length = ( int ) ( stream . Length - stream . Position ) ;
24
- using var nativeData = NSMutableData . FromLength ( length ) ;
23
+ using ( NSAutoreleasePool . Init ( ) )
24
+ {
25
+ int length = ( int ) ( stream . Length - stream . Position ) ;
26
+ var nativeData = NSMutableData . FromLength ( length ) ;
25
27
26
- var bytesSpan = new Span < byte > ( nativeData . MutableBytes , length ) ;
27
- stream . ReadExactly ( bytesSpan ) ;
28
+ var bytesSpan = new Span < byte > ( nativeData . MutableBytes , length ) ;
29
+ stream . ReadExactly ( bytesSpan ) ;
28
30
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 ) } .") ;
31
+ using var nsImage = NSImage . LoadFromData ( nativeData ) ;
32
+ if ( nsImage . Handle == IntPtr . Zero )
33
+ throw new ArgumentException ( $ "{ nameof ( Image ) } could not be created from { nameof ( stream ) } .") ;
32
34
33
- var cgImage = nsImage . CGImage ;
34
- return ImageFromCGImage < TPixel > ( cgImage ) ;
35
+ var cgImage = nsImage . CGImage ;
36
+ return ImageFromCGImage < TPixel > ( cgImage ) ;
37
+ }
35
38
}
36
39
}
37
40
}
Original file line number Diff line number Diff line change 5
5
6
6
using System ;
7
7
using osu . Framework . Platform . Apple . Native ;
8
- using osu . Framework . Platform . MacOS . Native ;
9
8
using osu . Framework . Platform . SDL2 ;
10
9
using osuTK ;
10
+ using Selector = osu . Framework . Platform . Apple . Native . Selector ;
11
11
12
12
namespace osu . Framework . Platform . MacOS
13
13
{
Original file line number Diff line number Diff line change 5
5
6
6
using System ;
7
7
using osu . Framework . Platform . Apple . Native ;
8
- using osu . Framework . Platform . MacOS . Native ;
9
8
using osu . Framework . Platform . SDL3 ;
10
9
using osuTK ;
10
+ using Selector = osu . Framework . Platform . Apple . Native . Selector ;
11
11
12
12
namespace osu . Framework . Platform . MacOS
13
13
{
You can’t perform that action at this time.
0 commit comments