Skip to content
Open
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
30 changes: 30 additions & 0 deletions osu.Framework.Android/AndroidGameSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using Android.Content;
using Android.Runtime;
using Org.Libsdl.App;
Expand Down Expand Up @@ -48,13 +49,15 @@

protected override void HandlePause()
{
setPreferredDisplayMode(false);
base.HandlePause();
isSurfaceReady = false;
}

protected override void HandleResume()
{
base.HandleResume();
setPreferredDisplayMode(true);
isSurfaceReady = true;
}

Expand All @@ -64,6 +67,33 @@
return base.OnApplyWindowInsets(view, insets);
}

private void setPreferredDisplayMode(bool enable)
{
var window = activity.Window;
var display = window?.DecorView?.Display;

if (window == null || display == null)
return;

var preferredMode = display.GetSupportedModes()

Check warning on line 78 in osu.Framework.Android/AndroidGameSurface.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

This call site is reachable on: 'Android' 21.0 and later. 'Display.Mode' is only supported on: 'android' 23.0 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 78 in osu.Framework.Android/AndroidGameSurface.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

Possible null reference argument for parameter 'source' in 'IOrderedEnumerable<Mode> Enumerable.OrderByDescending<Mode, float>(IEnumerable<Mode> source, Func<Mode, float> keySelector)'.

Check warning on line 78 in osu.Framework.Android/AndroidGameSurface.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

This call site is reachable on: 'Android' 21.0 and later. 'Display.GetSupportedModes()' is only supported on: 'android' 23.0 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 78 in osu.Framework.Android/AndroidGameSurface.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

This call site is reachable on: 'Android' 21.0 and later. 'Display.Mode' is only supported on: 'android' 23.0 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 78 in osu.Framework.Android/AndroidGameSurface.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

This call site is reachable on: 'Android' 21.0 and later. 'Display.Mode' is only supported on: 'android' 23.0 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 78 in osu.Framework.Android/AndroidGameSurface.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

Possible null reference argument for parameter 'source' in 'IOrderedEnumerable<Mode> Enumerable.OrderByDescending<Mode, float>(IEnumerable<Mode> source, Func<Mode, float> keySelector)'.
.OrderByDescending(mode => mode.RefreshRate)

Check warning on line 79 in osu.Framework.Android/AndroidGameSurface.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

This call site is reachable on: 'Android' 21.0 and later. 'Display.Mode.RefreshRate' is only supported on: 'android' 23.0 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
.FirstOrDefault();

if (preferredMode == null)
return;

var attributes = window.Attributes;
attributes.PreferredRefreshRate = enable ? preferredMode.RefreshRate : 0f;

Check warning on line 86 in osu.Framework.Android/AndroidGameSurface.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

Dereference of a possibly null reference.

Check warning on line 86 in osu.Framework.Android/AndroidGameSurface.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

This call site is reachable on: 'Android' 21.0 and later. 'Display.Mode.RefreshRate' is only supported on: 'android' 23.0 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 86 in osu.Framework.Android/AndroidGameSurface.cs

View workflow job for this annotation

GitHub Actions / Build only (Android)

Dereference of a possibly null reference.

if (OperatingSystem.IsAndroidVersionAtLeast(23))
attributes.PreferredDisplayModeId = enable ? preferredMode.ModeId : 0;

if (OperatingSystem.IsAndroidVersionAtLeast(30))
window.SetPreferMinimalPostProcessing(enable);

window.Attributes = attributes;
}

/// <summary>
/// Updates the <see cref="IWindow.SafeAreaPadding"/>, taking into account screen insets that may be obstructing this <see cref="AndroidGameSurface"/>.
/// </summary>
Expand Down
Loading