Add a level of indirection to DirectX/XAudio2 ctors and static calls

This commit is contained in:
YoshiRulz 2022-04-23 14:22:00 +10:00
parent 2fde1ce9e9
commit 8563be60ba
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
4 changed files with 34 additions and 7 deletions

View File

@ -0,0 +1,29 @@
#nullable enable
using System;
using System.Collections.Generic;
using BizHawk.Bizware.BizwareGL;
using BizHawk.Client.Common;
namespace BizHawk.Bizware.DirectX
{
/// <summary>An indirection, so that types from the SlimDX assembly don't need to be resolved if DirectX/XAudio2 features are never used.</summary>
public static class IndirectX
{
public static IGL CreateD3DGLImpl()
=> new IGL_SlimDX9();
public static ISoundOutput CreateDSSoundOutput(IHostAudioManager sound, IntPtr mainWindowHandle, string chosenDeviceName)
=> new DirectSoundSoundOutput(sound, mainWindowHandle, chosenDeviceName);
public static ISoundOutput CreateXAudio2SoundOutput(IHostAudioManager sound, string chosenDeviceName)
=> new XAudio2SoundOutput(sound, chosenDeviceName);
public static IEnumerable<string> GetDSSinkNames()
=> DirectSoundSoundOutput.GetDeviceNames();
public static IEnumerable<string> GetXAudio2SinkNames()
=> XAudio2SoundOutput.GetDeviceNames();
}
}

View File

@ -900,8 +900,8 @@ namespace BizHawk.Client.EmuHawk
{
static IEnumerable<string> GetDeviceNamesCallback(ESoundOutputMethod outputMethod) => outputMethod switch
{
ESoundOutputMethod.DirectSound => DirectSoundSoundOutput.GetDeviceNames(),
ESoundOutputMethod.XAudio2 => XAudio2SoundOutput.GetDeviceNames(),
ESoundOutputMethod.DirectSound => IndirectX.GetDSSinkNames(),
ESoundOutputMethod.XAudio2 => IndirectX.GetXAudio2SinkNames(),
ESoundOutputMethod.OpenAL => OpenALSoundOutput.GetDeviceNames(),
_ => Enumerable.Empty<string>()
};

View File

@ -181,17 +181,15 @@ namespace BizHawk.Client.EmuHawk
// possibly sharing config w/ Windows, assume the user wants the not-slow method (but don't change the config)
return TryInitIGL(EDispMethod.OpenGL);
}
IGL_SlimDX9 glSlimDX;
try
{
glSlimDX = new IGL_SlimDX9();
return CheckRenderer(IndirectX.CreateD3DGLImpl());
}
catch (Exception ex)
{
new ExceptionBox(new Exception("Initialization of Direct3d 9 Display Method failed; falling back to GDI+", ex)).ShowDialog();
return TryInitIGL(initialConfig.DispMethod = EDispMethod.GdiPlus);
}
return CheckRenderer(glSlimDX);
case EDispMethod.OpenGL:
var glOpenTK = new IGL_TK(2, 0, false);
if (glOpenTK.Version < 200)

View File

@ -51,8 +51,8 @@ namespace BizHawk.Client.EmuHawk
{
_outputDevice = config.SoundOutputMethod switch
{
ESoundOutputMethod.DirectSound => new DirectSoundSoundOutput(this, mainWindowHandle, config.SoundDevice),
ESoundOutputMethod.XAudio2 => new XAudio2SoundOutput(this, config.SoundDevice),
ESoundOutputMethod.DirectSound => IndirectX.CreateDSSoundOutput(this, mainWindowHandle, config.SoundDevice),
ESoundOutputMethod.XAudio2 => IndirectX.CreateXAudio2SoundOutput(this, config.SoundDevice),
ESoundOutputMethod.OpenAL => new OpenALSoundOutput(this, config.SoundDevice),
_ => new DummySoundOutput(this)
};