Skip to content

Commit

Permalink
Merge pull request #6292 from smoogipoo/bring-back-sdl2
Browse files Browse the repository at this point in the history
Bring back SDL2 by default, lock SDL3 behind environment variable
  • Loading branch information
peppy authored May 22, 2024
2 parents d48e771 + dc4b11f commit 1f6b157
Show file tree
Hide file tree
Showing 56 changed files with 5,104 additions and 259 deletions.
2 changes: 1 addition & 1 deletion osu.Framework.Android/AndroidGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace osu.Framework.Android
{
public class AndroidGameHost : SDL3GameHost
public class AndroidGameHost : SDLGameHost
{
private readonly AndroidGameActivity activity;

Expand Down
1 change: 1 addition & 0 deletions osu.Framework.Android/AndroidGameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using osu.Framework.Bindables;
using osu.Framework.Platform;
using osu.Framework.Platform.SDL3;

namespace osu.Framework.Android
{
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework.Tests/Visual/Platform/TestSceneBorderless.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class TestSceneBorderless : FrameworkTestScene
private readonly SpriteText currentWindowMode = new SpriteText();
private readonly SpriteText currentDisplay = new SpriteText();

private SDL3Window? window;
private ISDLWindow? window;
private readonly Bindable<WindowMode> windowMode = new Bindable<WindowMode>();

public TestSceneBorderless()
Expand Down Expand Up @@ -57,7 +57,7 @@ public TestSceneBorderless()
[BackgroundDependencyLoader]
private void load(FrameworkConfigManager config, GameHost host)
{
window = host.Window as SDL3Window;
window = host.Window as ISDLWindow;
config.BindWith(FrameworkSetting.WindowMode, windowMode);

windowMode.BindValueChanged(mode => currentWindowMode.Text = $"Window Mode: {mode.NewValue}", true);
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework.Tests/Visual/Platform/TestSceneFullscreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void TestScreenModeSwitch()
if (window.SupportedWindowModes.Contains(WindowMode.Fullscreen))
{
AddStep("change to fullscreen", () => windowMode.Value = WindowMode.Fullscreen);
AddAssert("window position updated", () => ((SDL3Window)window).Position, () => Is.EqualTo(window.CurrentDisplayBindable.Value.Bounds.Location));
AddAssert("window position updated", () => ((ISDLWindow)window).Position, () => Is.EqualTo(window.CurrentDisplayBindable.Value.Bounds.Location));
testResolution(1920, 1080);
testResolution(1280, 960);
testResolution(9999, 9999);
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework.Tests/Visual/Platform/TestSceneWindowed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public partial class TestSceneWindowed : FrameworkTestScene
[Resolved]
private FrameworkConfigManager config { get; set; }

private SDL3Window sdlWindow;
private ISDLWindow sdlWindow;

[BackgroundDependencyLoader]
private void load()
{
sdlWindow = (SDL3Window)host.Window;
sdlWindow = (ISDLWindow)host.Window;
Children = new Drawable[]
{
new FillFlowContainer
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework.Tests/Visual/Platform/WindowDisplaysPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public partial class WindowDisplaysPreview : Container
private static readonly Color4 window_fill = new Color4(95, 113, 197, 255);
private static readonly Color4 window_stroke = new Color4(36, 59, 166, 255);

private SDL3Window? window;
private ISDLWindow? window;
private readonly Bindable<WindowMode> windowMode = new Bindable<WindowMode>();
private readonly Bindable<Display> currentDisplay = new Bindable<Display>();

Expand Down Expand Up @@ -90,7 +90,7 @@ public WindowDisplaysPreview()
[BackgroundDependencyLoader]
private void load(FrameworkConfigManager config, GameHost host)
{
window = host.Window as SDL3Window;
window = host.Window as ISDLWindow;
config.BindWith(FrameworkSetting.WindowMode, windowMode);

if (window != null)
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework.iOS/IOSGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace osu.Framework.iOS
{
public class IOSGameHost : SDL3GameHost
public class IOSGameHost : SDLGameHost
{
public IOSGameHost()
: base(string.Empty)
Expand Down
1 change: 1 addition & 0 deletions osu.Framework.iOS/IOSWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Framework.Platform.SDL3;
using SDL;
using UIKit;

Expand Down
3 changes: 3 additions & 0 deletions osu.Framework/FrameworkEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static class FrameworkEnvironment
public static int? VertexBufferCount { get; }
public static bool NoStructuredBuffers { get; }
public static string? DeferredRendererEventsOutputPath { get; }
public static bool UseSDL3 { get; }

/// <summary>
/// Whether non-SSL requests should be allowed. Debug only. Defaults to disabled.
Expand Down Expand Up @@ -51,6 +52,8 @@ static FrameworkEnvironment()

if (DebugUtils.IsDebugBuild)
AllowInsecureRequests = parseBool(Environment.GetEnvironmentVariable("OSU_INSECURE_REQUESTS")) ?? false;

UseSDL3 = RuntimeInfo.IsMobile || (parseBool(Environment.GetEnvironmentVariable("OSU_SDL3")) ?? false);
}

private static bool? parseBool(string? value)
Expand Down
13 changes: 13 additions & 0 deletions osu.Framework/Graphics/Performance/PerformanceOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using osu.Framework.Input;
using osu.Framework.Input.Events;
using osu.Framework.Platform;
using osu.Framework.Platform.SDL2;
using osu.Framework.Platform.SDL3;
using osu.Framework.Threading;
using osuTK;
using osuTK.Graphics;
Expand Down Expand Up @@ -231,6 +233,17 @@ private void updateInfoText()
addHeader("Mode:");
addValue(configWindowMode.ToString());

switch (host.Window)
{
case SDL3Window:
addValue(" (SDL3)");
break;

case SDL2Window:
addValue(" (SDL2)");
break;
}

void addHeader(string text) => infoText.AddText($"{text} ", cp =>
{
cp.Padding = new MarginPadding { Left = 5 };
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Input/Handlers/Joystick/JoystickHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override bool Initialize(GameHost host)
if (!base.Initialize(host))
return false;

if (!(host.Window is SDL3Window window))
if (!(host.Window is ISDLWindow window))
return false;

Enabled.BindValueChanged(e =>
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Input/Handlers/Keyboard/KeyboardHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override bool Initialize(GameHost host)
if (!base.Initialize(host))
return false;

if (!(host.Window is SDL3Window window))
if (!(host.Window is ISDLWindow window))
return false;

Enabled.BindValueChanged(e =>
Expand Down
6 changes: 3 additions & 3 deletions osu.Framework/Input/Handlers/Mouse/MouseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace osu.Framework.Input.Handlers.Mouse
{
/// <summary>
/// Handles mouse events from an <see cref="SDL3Window"/>.
/// Handles mouse events from an <see cref="ISDLWindow"/>.
/// Will use relative mouse mode where possible.
/// </summary>
public class MouseHandler : InputHandler, IHasCursorSensitivity, INeedsMousePositionFeedback
Expand All @@ -41,7 +41,7 @@ public class MouseHandler : InputHandler, IHasCursorSensitivity, INeedsMousePosi

public override bool IsActive => true;

private SDL3Window window;
private ISDLWindow window;

private Vector2? lastPosition;

Expand Down Expand Up @@ -76,7 +76,7 @@ public override bool Initialize(GameHost host)
if (!base.Initialize(host))
return false;

if (!(host.Window is SDL3Window desktopWindow))
if (!(host.Window is ISDLWindow desktopWindow))
return false;

window = desktopWindow;
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Input/Handlers/Touch/TouchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override bool Initialize(GameHost host)
if (!base.Initialize(host))
return false;

if (!(host.Window is SDL3Window window))
if (!(host.Window is ISDLWindow window))
return false;

Enabled.BindValueChanged(enabled =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

namespace osu.Framework.Input
{
internal class SDL3WindowTextInput : TextInputSource
internal class SDLWindowTextInput : TextInputSource
{
private readonly SDL3Window window;
private readonly ISDLWindow window;

public SDL3WindowTextInput(SDL3Window window)
public SDLWindowTextInput(ISDLWindow window)
{
this.window = window;
}
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Input/UserInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private bool mouseOutsideAllDisplays(Vector2 mousePosition)
switch (Host.Window.WindowMode.Value)
{
case WindowMode.Windowed:
windowLocation = Host.Window is SDL3Window sdlWindow ? sdlWindow.Position : Point.Empty;
windowLocation = Host.Window is ISDLWindow sdlWindow ? sdlWindow.Position : Point.Empty;
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Platform/DesktopGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace osu.Framework.Platform
{
public abstract class DesktopGameHost : SDL3GameHost
public abstract class DesktopGameHost : SDLGameHost
{
private TcpIpcProvider ipcProvider;
private readonly int? ipcPort;
Expand Down
58 changes: 58 additions & 0 deletions osu.Framework/Platform/ISDLWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Drawing;
using osu.Framework.Bindables;
using osu.Framework.Input;
using osuTK;
using osuTK.Input;
using RectangleF = osu.Framework.Graphics.Primitives.RectangleF;

namespace osu.Framework.Platform
{
internal interface ISDLWindow : IWindow
{
event Action<JoystickButton> JoystickButtonDown;
event Action<JoystickButton> JoystickButtonUp;
event Action<JoystickAxisSource, float> JoystickAxisChanged;
event Action<Touch> TouchDown;
event Action<Touch> TouchUp;
event Action<Vector2> MouseMove;
event Action<Vector2> MouseMoveRelative;
event Action<MouseButton> MouseDown;
event Action<MouseButton> MouseUp;
event Action<Vector2, bool> MouseWheel;
event Action<Key> KeyDown;
event Action<Key> KeyUp;
event Action<string> TextInput;
event TextEditingDelegate TextEditing;
event Action<WindowState> WindowStateChanged;

Bindable<CursorState> CursorStateBindable { get; }

Point Position { get; }
Size Size { get; }
float Scale { get; }
bool Resizable { get; set; }

bool MouseAutoCapture { set; }
bool RelativeMouseMode { get; set; }
bool CapsLockPressed { get; }

void UpdateMousePosition(Vector2 position);

void StartTextInput(bool allowIme);
void StopTextInput();
void SetTextInputRect(RectangleF rectangle);
void ResetIme();
}

/// <summary>
/// Fired when text is edited, usually via IME composition.
/// </summary>
/// <param name="text">The composition text.</param>
/// <param name="start">The index of the selection start.</param>
/// <param name="length">The length of the selection.</param>
public delegate void TextEditingDelegate(string text, int start, int length);
}
12 changes: 4 additions & 8 deletions osu.Framework/Platform/Linux/LinuxGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using osu.Framework.Input;
using osu.Framework.Input.Handlers;
using osu.Framework.Input.Handlers.Mouse;
using SDL;

namespace osu.Framework.Platform.Linux
{
Expand All @@ -27,13 +26,10 @@ internal LinuxGameHost(string gameName, HostOptions? options)
BypassCompositor = Options.BypassCompositor;
}

protected override void SetupForRun()
{
SDL3.SDL_SetHint(SDL3.SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, BypassCompositor ? "1"u8 : "0"u8);
base.SetupForRun();
}

protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface) => new SDL3DesktopWindow(preferredSurface, Options.FriendlyGameName);
protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface)
=> FrameworkEnvironment.UseSDL3
? new SDL3LinuxWindow(preferredSurface, Options.FriendlyGameName, BypassCompositor)
: new SDL2LinuxWindow(preferredSurface, Options.FriendlyGameName, BypassCompositor);

protected override ReadableKeyCombinationProvider CreateReadableKeyCombinationProvider() => new LinuxReadableKeyCombinationProvider();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Input.Bindings;
using osu.Framework.Platform.SDL;
using osu.Framework.Platform.SDL3;
using SDL;

namespace osu.Framework.Platform.Linux
Expand Down
17 changes: 17 additions & 0 deletions osu.Framework/Platform/Linux/SDL2LinuxWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Platform.SDL2;
using static SDL2.SDL;

namespace osu.Framework.Platform.Linux
{
internal class SDL2LinuxWindow : SDL2DesktopWindow
{
public SDL2LinuxWindow(GraphicsSurfaceType surfaceType, string appName, bool bypassCompositor)
: base(surfaceType, appName)
{
SDL_SetHint(SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, bypassCompositor ? "1" : "0");
}
}
}
17 changes: 17 additions & 0 deletions osu.Framework/Platform/Linux/SDL3LinuxWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Platform.SDL3;
using static SDL.SDL3;

namespace osu.Framework.Platform.Linux
{
internal class SDL3LinuxWindow : SDL3DesktopWindow
{
public SDL3LinuxWindow(GraphicsSurfaceType surfaceType, string appName, bool bypassCompositor)
: base(surfaceType, appName)
{
SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, bypassCompositor ? "1"u8 : "0"u8);
}
}
}
5 changes: 4 additions & 1 deletion osu.Framework/Platform/MacOS/MacOSGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ internal MacOSGameHost(string gameName, HostOptions options)
{
}

protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface) => new MacOSWindow(preferredSurface, Options.FriendlyGameName);
protected override IWindow CreateWindow(GraphicsSurfaceType preferredSurface)
=> FrameworkEnvironment.UseSDL3
? new SDL3MacOSWindow(preferredSurface, Options.FriendlyGameName)
: new SDL2MacOSWindow(preferredSurface, Options.FriendlyGameName);

public override IEnumerable<string> UserStoragePaths
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Input.Bindings;
using osu.Framework.Platform.SDL;
using osu.Framework.Platform.SDL3;
using SDL;

namespace osu.Framework.Platform.MacOS
Expand Down
Loading

0 comments on commit 1f6b157

Please sign in to comment.