mirror of
https://github.com/par274/sharpemu.git
synced 2026-08-20 00:11:29 +08:00
1660111189
* Astrobot-video-fix * Astrobot-video-fix with updated files * Astrobot-video-fix with tests files
74 lines
1.8 KiB
C#
74 lines
1.8 KiB
C#
// Copyright (C) 2026 SharpEmu Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
namespace SharpEmu.Libs.VideoOut;
|
|
|
|
using SharpEmu.Libs.Gpu.Metal;
|
|
|
|
public enum HostWindowMode
|
|
{
|
|
Windowed,
|
|
Borderless,
|
|
ExclusiveFullscreen,
|
|
}
|
|
|
|
public enum HostScalingMode
|
|
{
|
|
Fit,
|
|
Cover,
|
|
Stretch,
|
|
Integer,
|
|
}
|
|
|
|
public enum HostHdrMode
|
|
{
|
|
Auto,
|
|
On,
|
|
Off,
|
|
}
|
|
|
|
public sealed record HostVideoOptions
|
|
{
|
|
public static HostVideoOptions Default { get; } = new();
|
|
|
|
public HostWindowMode WindowMode { get; init; } = HostWindowMode.Windowed;
|
|
|
|
public HostScalingMode ScalingMode { get; init; } = HostScalingMode.Fit;
|
|
|
|
public int Width { get; init; } = 1920;
|
|
|
|
public int Height { get; init; } = 1080;
|
|
|
|
public int DisplayIndex { get; init; }
|
|
|
|
public int RefreshRate { get; init; }
|
|
|
|
public bool VSync { get; init; } = true;
|
|
|
|
public HostHdrMode HdrMode { get; init; } = HostHdrMode.Auto;
|
|
|
|
public HostVideoOptions Normalize() => this with
|
|
{
|
|
Width = Math.Clamp(Width, 640, 16384),
|
|
Height = Math.Clamp(Height, 360, 16384),
|
|
DisplayIndex = Math.Max(0, DisplayIndex),
|
|
RefreshRate = Math.Clamp(RefreshRate, 0, 1000),
|
|
HdrMode = Enum.IsDefined(HdrMode) ? HdrMode : HostHdrMode.Auto,
|
|
};
|
|
}
|
|
|
|
public static class HostVideoHost
|
|
{
|
|
private static HostVideoOptions _currentOptions = HostVideoOptions.Default;
|
|
|
|
public static HostVideoOptions CurrentOptions => Volatile.Read(ref _currentOptions);
|
|
|
|
public static bool TryConfigureVideo(HostVideoOptions options)
|
|
{
|
|
var normalized = options.Normalize();
|
|
Volatile.Write(ref _currentOptions, normalized);
|
|
return VulkanVideoPresenter.TryConfigureVideo(normalized) &
|
|
MetalVideoPresenter.TryConfigureVideo(normalized);
|
|
}
|
|
}
|