Decouple RenderTargetWrapper from GDI+ implementations

This commit is contained in:
YoshiRulz 2021-06-15 09:45:23 +10:00
parent 984982cd9b
commit bf4bac93b9
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 17 additions and 13 deletions

View File

@ -1,9 +1,14 @@
using System;
using System.Drawing;
namespace BizHawk.Bizware.BizwareGL
{
public interface IGraphicsControl : IDisposable
{
Rectangle ClientRectangle { get; }
Graphics CreateGraphics();
/// <summary>
/// Sets whether presentation operations on this control will vsync
/// </summary>

View File

@ -15,11 +15,6 @@ namespace BizHawk.Client.EmuHawk
// rendering state
private RenderTarget _currRenderTarget;
public IGL_GdiPlus()
{
MyBufferedGraphicsContext = new BufferedGraphicsContext();
}
void IDisposable.Dispose()
{
}
@ -267,7 +262,7 @@ namespace BizHawk.Client.EmuHawk
var ret = new GLControlWrapper_GdiPlus(this);
// create a render target for this control
var rtw = new RenderTargetWrapper(this) { Control = ret };
var rtw = new RenderTargetWrapper(() => MyBufferedGraphicsContext, ret);
ret.RenderTargetWrapper = rtw;
return ret;
@ -287,7 +282,7 @@ namespace BizHawk.Client.EmuHawk
};
var tex = new Texture2d(this, tw, w, h);
var rtw = new RenderTargetWrapper(this);
var rtw = new RenderTargetWrapper(() => MyBufferedGraphicsContext);
var rt = new RenderTarget(this, rtw, tex);
rtw.Target = rt;
return rt;
@ -342,7 +337,7 @@ namespace BizHawk.Client.EmuHawk
public GLControlWrapper_GdiPlus CurrentControl;
public RenderTargetWrapper CurrentRenderTargetWrapper;
public BufferedGraphicsContext MyBufferedGraphicsContext;
public readonly BufferedGraphicsContext MyBufferedGraphicsContext = new();
} //class IGL_GdiPlus

View File

@ -1,3 +1,4 @@
using System;
using System.Drawing;
using BizHawk.Bizware.BizwareGL;
@ -6,21 +7,24 @@ namespace BizHawk.Client.EmuHawk
{
public class RenderTargetWrapper
{
public RenderTargetWrapper(IGL_GdiPlus gdi)
public RenderTargetWrapper(
Func<BufferedGraphicsContext> getBufferedGraphicsContext,
IGraphicsControl control = null)
{
Gdi = gdi;
_getBufferedGraphicsContext = getBufferedGraphicsContext;
Control = control;
}
public void Dispose()
{
}
private readonly IGL_GdiPlus Gdi;
private readonly Func<BufferedGraphicsContext> _getBufferedGraphicsContext;
/// <summary>
/// the control associated with this render target (if any)
/// </summary>
public GLControlWrapper_GdiPlus Control;
private readonly IGraphicsControl Control;
/// <summary>
/// the offscreen render target, if that's what this is representing
@ -47,7 +51,7 @@ namespace BizHawk.Client.EmuHawk
}
MyBufferedGraphics?.Dispose();
MyBufferedGraphics = Gdi.MyBufferedGraphicsContext.Allocate(refGraphics, r);
MyBufferedGraphics = _getBufferedGraphicsContext().Allocate(refGraphics, r);
// MyBufferedGraphics.Graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;
//not sure about this stuff...