Completely divorce IVideoProvider from IEmulator, use a NullVideo implementation in MainForm if a core does not provide one, Remove VideoProviderGlue. Note that NullEmulator does implement IVideoProvider still, since we like to have fun with that one
This commit is contained in:
parent
2cf14db2ec
commit
4d1629e271
|
@ -722,9 +722,22 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public IEmulator Emulator
|
public IEmulator Emulator
|
||||||
{
|
{
|
||||||
get { return Global.Emulator; }
|
get { return Global.Emulator; }
|
||||||
set { Global.Emulator = value; }
|
set
|
||||||
|
{
|
||||||
|
Global.Emulator = value;
|
||||||
|
if (Global.Emulator.HasVideoProvider())
|
||||||
|
{
|
||||||
|
_currentVideoProvider = Global.Emulator.AsVideoProvider();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_currentVideoProvider = NullVideo.Instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IVideoProvider _currentVideoProvider = NullVideo.Instance;
|
||||||
|
|
||||||
protected override void OnActivated(EventArgs e)
|
protected override void OnActivated(EventArgs e)
|
||||||
{
|
{
|
||||||
base.OnActivated(e);
|
base.OnActivated(e);
|
||||||
|
@ -840,19 +853,18 @@ namespace BizHawk.Client.EmuHawk
|
||||||
// also handle floats
|
// also handle floats
|
||||||
conInput.AcceptNewFloats(Input.Instance.GetFloats().Select(o =>
|
conInput.AcceptNewFloats(Input.Instance.GetFloats().Select(o =>
|
||||||
{
|
{
|
||||||
var video = Emulator.VideoProvider();
|
|
||||||
// hackish
|
// hackish
|
||||||
if (o.Item1 == "WMouse X")
|
if (o.Item1 == "WMouse X")
|
||||||
{
|
{
|
||||||
var P = GlobalWin.DisplayManager.UntransformPoint(new Point((int)o.Item2, 0));
|
var P = GlobalWin.DisplayManager.UntransformPoint(new Point((int)o.Item2, 0));
|
||||||
float x = P.X / (float)video.BufferWidth;
|
float x = P.X / (float)_currentVideoProvider.BufferWidth;
|
||||||
return new Tuple<string, float>("WMouse X", x * 20000 - 10000);
|
return new Tuple<string, float>("WMouse X", x * 20000 - 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (o.Item1 == "WMouse Y")
|
if (o.Item1 == "WMouse Y")
|
||||||
{
|
{
|
||||||
var P = GlobalWin.DisplayManager.UntransformPoint(new Point(0, (int)o.Item2));
|
var P = GlobalWin.DisplayManager.UntransformPoint(new Point(0, (int)o.Item2));
|
||||||
float y = P.Y / (float)video.BufferHeight;
|
float y = P.Y / (float)_currentVideoProvider.BufferHeight;
|
||||||
return new Tuple<string, float>("WMouse Y", y * 20000 - 10000);
|
return new Tuple<string, float>("WMouse Y", y * 20000 - 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -918,7 +930,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public void TakeScreenshotClientToClipboard()
|
public void TakeScreenshotClientToClipboard()
|
||||||
{
|
{
|
||||||
using (var bb = GlobalWin.DisplayManager.RenderOffscreen(Emulator.AsVideoProvider(), Global.Config.Screenshot_CaptureOSD))
|
using (var bb = GlobalWin.DisplayManager.RenderOffscreen(_currentVideoProvider, Global.Config.Screenshot_CaptureOSD))
|
||||||
{
|
{
|
||||||
using (var img = bb.ToSysdrawingBitmap())
|
using (var img = bb.ToSysdrawingBitmap())
|
||||||
Clipboard.SetImage(img);
|
Clipboard.SetImage(img);
|
||||||
|
@ -979,7 +991,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
// run this entire thing exactly twice, since the first resize may adjust the menu stacking
|
// run this entire thing exactly twice, since the first resize may adjust the menu stacking
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
var video = Emulator.VideoProvider();
|
|
||||||
int zoom = Global.Config.TargetZoomFactors[Emulator.SystemId];
|
int zoom = Global.Config.TargetZoomFactors[Emulator.SystemId];
|
||||||
var area = Screen.FromControl(this).WorkingArea;
|
var area = Screen.FromControl(this).WorkingArea;
|
||||||
|
|
||||||
|
@ -990,7 +1001,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Size lastComputedSize = new Size(1, 1);
|
Size lastComputedSize = new Size(1, 1);
|
||||||
for (; zoom >= 1; zoom--)
|
for (; zoom >= 1; zoom--)
|
||||||
{
|
{
|
||||||
lastComputedSize = GlobalWin.DisplayManager.CalculateClientSize(video, zoom);
|
lastComputedSize = GlobalWin.DisplayManager.CalculateClientSize(_currentVideoProvider, zoom);
|
||||||
if ((((lastComputedSize.Width) + borderWidth) < area.Width)
|
if ((((lastComputedSize.Width) + borderWidth) < area.Width)
|
||||||
&& (((lastComputedSize.Height) + borderHeight) < area.Height))
|
&& (((lastComputedSize.Height) + borderHeight) < area.Height))
|
||||||
{
|
{
|
||||||
|
@ -1901,7 +1912,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
private BitmapBuffer MakeScreenshotImage()
|
private BitmapBuffer MakeScreenshotImage()
|
||||||
{
|
{
|
||||||
return GlobalWin.DisplayManager.RenderVideoProvider(Emulator.AsVideoProvider());
|
return GlobalWin.DisplayManager.RenderVideoProvider(_currentVideoProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveSlotSelectedMessage()
|
private void SaveSlotSelectedMessage()
|
||||||
|
@ -1919,7 +1930,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//private Size _lastVideoSize = new Size(-1, -1), _lastVirtualSize = new Size(-1, -1);
|
//private Size _lastVideoSize = new Size(-1, -1), _lastVirtualSize = new Size(-1, -1);
|
||||||
var video = Emulator.VideoProvider();
|
var video = _currentVideoProvider;
|
||||||
//bool change = false;
|
//bool change = false;
|
||||||
Size currVideoSize = new Size(video.BufferWidth, video.BufferHeight);
|
Size currVideoSize = new Size(video.BufferWidth, video.BufferHeight);
|
||||||
Size currVirtualSize = new Size(video.VirtualWidth, video.VirtualHeight);
|
Size currVirtualSize = new Size(video.VirtualWidth, video.VirtualHeight);
|
||||||
|
@ -2269,7 +2280,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public BitmapBuffer CaptureOSD()
|
public BitmapBuffer CaptureOSD()
|
||||||
{
|
{
|
||||||
var bb = GlobalWin.DisplayManager.RenderOffscreen(Emulator.AsVideoProvider(), true);
|
var bb = GlobalWin.DisplayManager.RenderOffscreen(_currentVideoProvider, true);
|
||||||
bb.DiscardAlpha();
|
bb.DiscardAlpha();
|
||||||
return bb;
|
return bb;
|
||||||
}
|
}
|
||||||
|
@ -2990,8 +3001,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var videoProvider = Emulator.AsVideoProvider();
|
aw.SetVideoParameters(_currentVideoProvider.BufferWidth, _currentVideoProvider.BufferHeight);
|
||||||
aw.SetVideoParameters(videoProvider.BufferWidth, videoProvider.BufferHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aw.SetAudioParameters(44100, 2, 16);
|
aw.SetAudioParameters(44100, 2, 16);
|
||||||
|
@ -3168,8 +3178,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var videoProvider = Emulator.AsVideoProvider();
|
bbin = new BitmapBuffer(_currentVideoProvider.BufferWidth, _currentVideoProvider.BufferHeight, _currentVideoProvider.GetVideoBuffer());
|
||||||
bbin = new BitmapBuffer(videoProvider.BufferWidth, videoProvider.BufferHeight, videoProvider.GetVideoBuffer());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bbin.DiscardAlpha();
|
bbin.DiscardAlpha();
|
||||||
|
@ -3180,7 +3189,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
if (_avwriterpad)
|
if (_avwriterpad)
|
||||||
{
|
{
|
||||||
g.Clear(Color.FromArgb(Emulator.AsVideoProvider().BackgroundColor));
|
g.Clear(Color.FromArgb(_currentVideoProvider.BackgroundColor));
|
||||||
g.DrawImageUnscaled(bmpin, (bmpout.Width - bmpin.Width) / 2, (bmpout.Height - bmpin.Height) / 2);
|
g.DrawImageUnscaled(bmpin, (bmpout.Width - bmpin.Width) / 2, (bmpout.Height - bmpin.Height) / 2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -3208,7 +3217,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
disposableOutput = (IDisposable)output;
|
disposableOutput = (IDisposable)output;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
output = Emulator.AsVideoProvider();
|
output = _currentVideoProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
_currAviWriter.SetFrame(Emulator.Frame);
|
_currAviWriter.SetFrame(Emulator.Frame);
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
namespace BizHawk.Emulation.Common
|
||||||
|
{
|
||||||
|
// A default IVideoProvider implementation that simply returns a black screen
|
||||||
|
public class NullVideo : IVideoProvider
|
||||||
|
{
|
||||||
|
public int[] GetVideoBuffer()
|
||||||
|
{
|
||||||
|
return new int[BufferWidth * BufferHeight];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int VirtualWidth { get { return 256; } }
|
||||||
|
public int VirtualHeight { get { return 192; } }
|
||||||
|
|
||||||
|
public int BufferWidth { get { return 256; } }
|
||||||
|
public int BufferHeight { get { return 192; } }
|
||||||
|
|
||||||
|
public int BackgroundColor { get { return 0; } }
|
||||||
|
|
||||||
|
public static NullVideo Instance
|
||||||
|
{
|
||||||
|
get { return new NullVideo(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -101,6 +101,7 @@
|
||||||
<Compile Include="Base Implementations\NullController.cs" />
|
<Compile Include="Base Implementations\NullController.cs" />
|
||||||
<Compile Include="Base Implementations\NullEmulator.cs" />
|
<Compile Include="Base Implementations\NullEmulator.cs" />
|
||||||
<Compile Include="Base Implementations\NullSound.cs" />
|
<Compile Include="Base Implementations\NullSound.cs" />
|
||||||
|
<Compile Include="Base Implementations\NullVideo.cs" />
|
||||||
<Compile Include="Base Implementations\TraceBuffer.cs" />
|
<Compile Include="Base Implementations\TraceBuffer.cs" />
|
||||||
<Compile Include="BinaryQuickSerializer.cs" />
|
<Compile Include="BinaryQuickSerializer.cs" />
|
||||||
<Compile Include="BizInvoke\BizInvoker.cs" />
|
<Compile Include="BizInvoke\BizInvoker.cs" />
|
||||||
|
|
|
@ -77,13 +77,4 @@ namespace BizHawk.Emulation.Common
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CoreComm CoreComm { get; }
|
CoreComm CoreComm { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class VideoProviderGlue
|
|
||||||
{
|
|
||||||
// todo: this will go away
|
|
||||||
public static IVideoProvider VideoProvider(this IEmulator emu)
|
|
||||||
{
|
|
||||||
return emu.ServiceProvider.GetService<IVideoProvider>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue