Skip to content

Commit d73af6c

Browse files
authored
Merge pull request #6268 from Susko3/dont-overload-DisplayHandle
Refactor `DisplayHandle` into seperate android and linux properties
2 parents f7718ea + 60c4f25 commit d73af6c

File tree

7 files changed

+30
-12
lines changed

7 files changed

+30
-12
lines changed

osu.Framework.Android/AndroidGameWindow.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace osu.Framework.Android
99
{
1010
internal class AndroidGameWindow : SDL3MobileWindow
1111
{
12-
public override IntPtr DisplayHandle => AndroidGameActivity.Surface.NativeSurface?.Handle ?? IntPtr.Zero;
12+
public override IntPtr SurfaceHandle => AndroidGameActivity.Surface.NativeSurface?.Handle ?? IntPtr.Zero;
1313

1414
public AndroidGameWindow(GraphicsSurfaceType surfaceType, string appName)
1515
: base(surfaceType, appName)

osu.Framework/Graphics/Veldrid/VeldridDevice.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ public VeldridDevice(IGraphicsSurface graphicsSurface)
162162
{
163163
var linuxGraphics = (ILinuxGraphicsSurface)this.graphicsSurface;
164164
swapchain.Source = linuxGraphics.IsWayland
165-
? SwapchainSource.CreateWayland(this.graphicsSurface.DisplayHandle, this.graphicsSurface.WindowHandle)
166-
: SwapchainSource.CreateXlib(this.graphicsSurface.DisplayHandle, this.graphicsSurface.WindowHandle);
165+
? SwapchainSource.CreateWayland(linuxGraphics.DisplayHandle, this.graphicsSurface.WindowHandle)
166+
: SwapchainSource.CreateXlib(linuxGraphics.DisplayHandle, this.graphicsSurface.WindowHandle);
167167
break;
168168
}
169169

170170
case RuntimeInfo.Platform.Android:
171171
{
172172
var androidGraphics = (IAndroidGraphicsSurface)this.graphicsSurface;
173-
swapchain.Source = SwapchainSource.CreateAndroidSurface(this.graphicsSurface.DisplayHandle, androidGraphics.JniEnvHandle);
173+
swapchain.Source = SwapchainSource.CreateAndroidSurface(androidGraphics.SurfaceHandle, androidGraphics.JniEnvHandle);
174174
break;
175175
}
176176
}

osu.Framework/Platform/IAndroidGraphicsSurface.cs

+6
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,11 @@ public interface IAndroidGraphicsSurface
1111
/// Returns JNI environment handle.
1212
/// </summary>
1313
IntPtr JniEnvHandle { get; }
14+
15+
/// <summary>
16+
/// Android Surface handle.
17+
/// </summary>
18+
/// <remarks>https://developer.android.com/reference/android/view/Surface.html</remarks>
19+
IntPtr SurfaceHandle { get; }
1420
}
1521
}

osu.Framework/Platform/IGraphicsSurface.cs

-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ public interface IGraphicsSurface
1616
/// </summary>
1717
IntPtr WindowHandle { get; }
1818

19-
/// <summary>
20-
/// A pointer representing a handle to the display containing this window, provided by the operating system.
21-
/// This is specific to X11/Wayland subsystems.
22-
/// </summary>
23-
IntPtr DisplayHandle { get; }
24-
2519
/// <summary>
2620
/// The type of surface.
2721
/// </summary>

osu.Framework/Platform/ILinuxGraphicsSurface.cs

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4+
using System;
5+
46
namespace osu.Framework.Platform
57
{
68
public interface ILinuxGraphicsSurface
@@ -9,5 +11,11 @@ public interface ILinuxGraphicsSurface
911
/// Whether the current display server is Wayland.
1012
/// </summary>
1113
bool IsWayland { get; }
14+
15+
/// <summary>
16+
/// A pointer representing a handle to the display containing this window, provided by the operating system.
17+
/// This is specific to X11/Wayland subsystems.
18+
/// </summary>
19+
IntPtr DisplayHandle { get; }
1220
}
1321
}

osu.Framework/Platform/SDL/SDL3GraphicsSurface.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ internal unsafe class SDL3GraphicsSurface : IGraphicsSurface, IOpenGLGraphicsSur
2121
private IntPtr context;
2222

2323
public IntPtr WindowHandle => window.WindowHandle;
24-
public IntPtr DisplayHandle => window.DisplayHandle;
2524

2625
public GraphicsSurfaceType Type { get; }
2726

@@ -216,13 +215,19 @@ bool IOpenGLGraphicsSurface.VerticalSync
216215

217216
bool ILinuxGraphicsSurface.IsWayland => window.IsWayland;
218217

218+
[SupportedOSPlatform("linux")]
219+
IntPtr ILinuxGraphicsSurface.DisplayHandle => window.DisplayHandle;
220+
219221
#endregion
220222

221223
#region Android-specific implementation
222224

223225
[SupportedOSPlatform("android")]
224226
IntPtr IAndroidGraphicsSurface.JniEnvHandle => SDL3.SDL_AndroidGetJNIEnv();
225227

228+
[SupportedOSPlatform("android")]
229+
IntPtr IAndroidGraphicsSurface.SurfaceHandle => window.SurfaceHandle;
230+
226231
#endregion
227232
}
228233
}

osu.Framework/Platform/SDL3Window.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Runtime.CompilerServices;
77
using System.Runtime.InteropServices;
8+
using System.Runtime.Versioning;
89
using osu.Framework.Allocation;
910
using osu.Framework.Bindables;
1011
using osu.Framework.Configuration;
@@ -119,7 +120,8 @@ public IntPtr WindowHandle
119120
}
120121
}
121122

122-
public virtual IntPtr DisplayHandle
123+
[SupportedOSPlatform("linux")]
124+
public IntPtr DisplayHandle
123125
{
124126
get
125127
{
@@ -138,6 +140,9 @@ public virtual IntPtr DisplayHandle
138140
}
139141
}
140142

143+
[SupportedOSPlatform("android")]
144+
public virtual IntPtr SurfaceHandle => throw new PlatformNotSupportedException();
145+
141146
public bool CapsLockPressed => SDL3.SDL_GetModState().HasFlagFast(SDL_Keymod.SDL_KMOD_CAPS);
142147

143148
/// <summary>

0 commit comments

Comments
 (0)