Misc. cleanup in DisplayManager
added a Deconstruct extension for Size
This commit is contained in:
parent
101c04de1b
commit
9f7057f09d
|
@ -0,0 +1,13 @@
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace BizHawk.Bizware.BizwareGL.DrawingExtensions
|
||||||
|
{
|
||||||
|
public static class DrawingExtensions
|
||||||
|
{
|
||||||
|
public static void Deconstruct(this Size size, out int width, out int height)
|
||||||
|
{
|
||||||
|
width = size.Width;
|
||||||
|
height = size.Height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ using System.Drawing.Text;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
using BizHawk.Bizware.BizwareGL;
|
using BizHawk.Bizware.BizwareGL;
|
||||||
|
using BizHawk.Bizware.BizwareGL.DrawingExtensions;
|
||||||
using BizHawk.Bizware.DirectX;
|
using BizHawk.Bizware.DirectX;
|
||||||
using BizHawk.Bizware.OpenTK3;
|
using BizHawk.Bizware.OpenTK3;
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
|
@ -68,7 +69,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
_glManager = GLManager.Instance;
|
_glManager = GLManager.Instance;
|
||||||
|
|
||||||
this._presentationPanel = presentationPanel;
|
this._presentationPanel = presentationPanel;
|
||||||
_graphicsControl = this._presentationPanel.GraphicsControl;
|
|
||||||
_crGraphicsControl = _glManager.GetContextForGraphicsControl(_graphicsControl);
|
_crGraphicsControl = _glManager.GetContextForGraphicsControl(_graphicsControl);
|
||||||
|
|
||||||
// it's sort of important for these to be initialized to something nonzero
|
// it's sort of important for these to be initialized to something nonzero
|
||||||
|
@ -171,10 +171,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
// layer resources
|
// layer resources
|
||||||
private readonly PresentationPanel _presentationPanel; // well, its the final layer's target, at least
|
private readonly PresentationPanel _presentationPanel; // well, its the final layer's target, at least
|
||||||
private readonly GraphicsControl _graphicsControl; // well, its the final layer's target, at least
|
|
||||||
private readonly GLManager.ContextRef _crGraphicsControl;
|
private readonly GLManager.ContextRef _crGraphicsControl;
|
||||||
private FilterProgram _currentFilterProgram;
|
private FilterProgram _currentFilterProgram;
|
||||||
|
|
||||||
|
private GraphicsControl _graphicsControl => _presentationPanel.GraphicsControl;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// these variables will track the dimensions of the last frame's (or the next frame? this is confusing) emulator native output size
|
/// these variables will track the dimensions of the last frame's (or the next frame? this is confusing) emulator native output size
|
||||||
/// THIS IS OLD JUNK. I should get rid of it, I think. complex results from the last filter ingestion should be saved instead.
|
/// THIS IS OLD JUNK. I should get rid of it, I think. complex results from the last filter ingestion should be saved instead.
|
||||||
|
@ -202,6 +203,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
private readonly RetroShaderChain _shaderChainHq2X, _shaderChainScanlines, _shaderChainBicubic;
|
private readonly RetroShaderChain _shaderChainHq2X, _shaderChainScanlines, _shaderChainBicubic;
|
||||||
private RetroShaderChain _shaderChainUser;
|
private RetroShaderChain _shaderChainUser;
|
||||||
|
|
||||||
|
private void ActivateGLContext() => _glManager.Activate(_crGraphicsControl);
|
||||||
|
|
||||||
|
private void SwapBuffersOfGraphicsControl() => _graphicsControl.SwapBuffers();
|
||||||
|
|
||||||
public void RefreshUserShader()
|
public void RefreshUserShader()
|
||||||
{
|
{
|
||||||
_shaderChainUser?.Dispose();
|
_shaderChainUser?.Dispose();
|
||||||
|
@ -419,13 +424,15 @@ namespace BizHawk.Client.EmuHawk
|
||||||
chain.AddFilter(fLuaLayer, surfaceID.GetName());
|
chain.AddFilter(fLuaLayer, surfaceID.GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Point GraphicsControlPointToClient(Point p) => _graphicsControl.PointToClient(p);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Using the current filter program, turn a mouse coordinate from window space to the original emulator screen space.
|
/// Using the current filter program, turn a mouse coordinate from window space to the original emulator screen space.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Point UntransformPoint(Point p)
|
public Point UntransformPoint(Point p)
|
||||||
{
|
{
|
||||||
// first, turn it into a window coordinate
|
// first, turn it into a window coordinate
|
||||||
p = _presentationPanel.Control.PointToClient(p);
|
p = GraphicsControlPointToClient(p);
|
||||||
|
|
||||||
// now, if there's no filter program active, just give up
|
// now, if there's no filter program active, just give up
|
||||||
if (_currentFilterProgram == null) return p;
|
if (_currentFilterProgram == null) return p;
|
||||||
|
@ -464,6 +471,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public Size GetPanelNativeSize() => _presentationPanel.NativeSize;
|
public Size GetPanelNativeSize() => _presentationPanel.NativeSize;
|
||||||
|
|
||||||
|
private Size GetGraphicsControlSize() => _graphicsControl.Size;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This will receive an emulated output frame from an IVideoProvider and run it through the complete frame processing pipeline
|
/// This will receive an emulated output frame from an IVideoProvider and run it through the complete frame processing pipeline
|
||||||
/// Then it will stuff it into the bound PresentationPanel.
|
/// Then it will stuff it into the bound PresentationPanel.
|
||||||
|
@ -478,7 +487,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
VideoProvider = videoProvider,
|
VideoProvider = videoProvider,
|
||||||
Simulate = displayNothing,
|
Simulate = displayNothing,
|
||||||
ChainOutsize = _graphicsControl.Size,
|
ChainOutsize = GetGraphicsControlSize(),
|
||||||
IncludeOSD = true,
|
IncludeOSD = true,
|
||||||
IncludeUserFilters = true
|
IncludeUserFilters = true
|
||||||
};
|
};
|
||||||
|
@ -527,7 +536,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
VideoProvider = videoProvider,
|
VideoProvider = videoProvider,
|
||||||
Simulate = false,
|
Simulate = false,
|
||||||
ChainOutsize = _graphicsControl.Size,
|
ChainOutsize = GetGraphicsControlSize(),
|
||||||
Offscreen = true,
|
Offscreen = true,
|
||||||
IncludeOSD = includeOSD,
|
IncludeOSD = includeOSD,
|
||||||
IncludeUserFilters = true,
|
IncludeUserFilters = true,
|
||||||
|
@ -782,7 +791,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
//no drawing actually happens. it's important not to begin drawing on a control
|
//no drawing actually happens. it's important not to begin drawing on a control
|
||||||
if (!job.Simulate && !job.Offscreen)
|
if (!job.Simulate && !job.Offscreen)
|
||||||
{
|
{
|
||||||
_glManager.Activate(_crGraphicsControl);
|
ActivateGLContext();
|
||||||
|
|
||||||
if (job.ChainOutsize.Width == 0 || job.ChainOutsize.Height == 0)
|
if (job.ChainOutsize.Width == 0 || job.ChainOutsize.Height == 0)
|
||||||
{
|
{
|
||||||
|
@ -935,13 +944,13 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public void Blank()
|
public void Blank()
|
||||||
{
|
{
|
||||||
_glManager.Activate(_crGraphicsControl);
|
ActivateGLContext();
|
||||||
_gl.BeginScene();
|
_gl.BeginScene();
|
||||||
_gl.BindRenderTarget(null);
|
_gl.BindRenderTarget(null);
|
||||||
_gl.SetClearColor(Color.Black);
|
_gl.SetClearColor(Color.Black);
|
||||||
_gl.Clear(ClearBufferMask.ColorBufferBit);
|
_gl.Clear(ClearBufferMask.ColorBufferBit);
|
||||||
_gl.EndScene();
|
_gl.EndScene();
|
||||||
_presentationPanel.GraphicsControl.SwapBuffers();
|
SwapBuffersOfGraphicsControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateSourceDrawingWork(JobInfo job)
|
private void UpdateSourceDrawingWork(JobInfo job)
|
||||||
|
@ -979,15 +988,15 @@ namespace BizHawk.Client.EmuHawk
|
||||||
//TODO - whats so hard about triple buffering anyway? just enable it always, and change api to SetVsync(enable,throttle)
|
//TODO - whats so hard about triple buffering anyway? just enable it always, and change api to SetVsync(enable,throttle)
|
||||||
//maybe even SetVsync(enable,throttlemethod) or just SetVsync(enable,throttle,advanced)
|
//maybe even SetVsync(enable,throttlemethod) or just SetVsync(enable,throttle,advanced)
|
||||||
|
|
||||||
if (_lastVsyncSetting != vsync || _lastVsyncSettingGraphicsControl != _presentationPanel.GraphicsControl)
|
if (_lastVsyncSetting != vsync || _lastVsyncSettingGraphicsControl != _graphicsControl)
|
||||||
{
|
{
|
||||||
if (_lastVsyncSetting == null && vsync)
|
if (_lastVsyncSetting == null && vsync)
|
||||||
{
|
{
|
||||||
// Workaround for vsync not taking effect at startup (Intel graphics related?)
|
// Workaround for vsync not taking effect at startup (Intel graphics related?)
|
||||||
_presentationPanel.GraphicsControl.SetVsync(false);
|
_graphicsControl.SetVsync(false);
|
||||||
}
|
}
|
||||||
_presentationPanel.GraphicsControl.SetVsync(vsync);
|
_graphicsControl.SetVsync(vsync);
|
||||||
_lastVsyncSettingGraphicsControl = _presentationPanel.GraphicsControl;
|
_lastVsyncSettingGraphicsControl = _graphicsControl;
|
||||||
_lastVsyncSetting = vsync;
|
_lastVsyncSetting = vsync;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1054,23 +1063,22 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
job.OffscreenBb = rtCurr.Texture2d.Resolve();
|
job.OffscreenBb = rtCurr.Texture2d.Resolve();
|
||||||
job.OffscreenBb.DiscardAlpha();
|
job.OffscreenBb.DiscardAlpha();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.Assert(inFinalTarget);
|
|
||||||
|
|
||||||
// wait for vsync to begin
|
Debug.Assert(inFinalTarget);
|
||||||
if (alternateVsync) dx9.AlternateVsyncPass(0);
|
|
||||||
|
|
||||||
// present and conclude drawing
|
// wait for vsync to begin
|
||||||
_presentationPanel.GraphicsControl.SwapBuffers();
|
if (alternateVsync) dx9.AlternateVsyncPass(0);
|
||||||
|
|
||||||
// wait for vsync to end
|
// present and conclude drawing
|
||||||
if (alternateVsync) dx9.AlternateVsyncPass(1);
|
_graphicsControl.SwapBuffers();
|
||||||
|
|
||||||
// nope. don't do this. workaround for slow context switching on intel GPUs. just switch to another context when necessary before doing anything
|
// wait for vsync to end
|
||||||
// presentationPanel.GraphicsControl.End();
|
if (alternateVsync) dx9.AlternateVsyncPass(1);
|
||||||
}
|
|
||||||
|
// nope. don't do this. workaround for slow context switching on intel GPUs. just switch to another context when necessary before doing anything
|
||||||
|
// presentationPanel.GraphicsControl.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadCustomFont(Stream fontStream)
|
private void LoadCustomFont(Stream fontStream)
|
||||||
|
@ -1118,9 +1126,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
|
|
||||||
// placeholder logic for more abstracted surface definitions from filter chain
|
// placeholder logic for more abstracted surface definitions from filter chain
|
||||||
int currNativeWidth = _presentationPanel.NativeSize.Width;
|
var (currNativeWidth, currNativeHeight) = GetPanelNativeSize();
|
||||||
int currNativeHeight = _presentationPanel.NativeSize.Height;
|
|
||||||
|
|
||||||
currNativeWidth += ClientExtraPadding.Left + ClientExtraPadding.Right;
|
currNativeWidth += ClientExtraPadding.Left + ClientExtraPadding.Right;
|
||||||
currNativeHeight += ClientExtraPadding.Top + ClientExtraPadding.Bottom;
|
currNativeHeight += ClientExtraPadding.Top + ClientExtraPadding.Bottom;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue