diff --git a/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs b/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs index 2c80ba8d64..8cdac8fa3d 100644 --- a/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs @@ -39,9 +39,9 @@ namespace BizHawk.Client.Common private Color? _defaultTextBackground = Color.FromArgb(128, 0, 0, 0); - private DisplaySurface _clientSurface; + private IDisplaySurface _clientSurface; - private DisplaySurface _GUISurface; + private IDisplaySurface _GUISurface; private (int Left, int Top, int Right, int Bottom) _padding = (0, 0, 0, 0); @@ -73,7 +73,7 @@ namespace BizHawk.Client.Common public void SetAttributes(ImageAttributes a) => _attributes = a; - private DisplaySurface GetRelevantSurface(DisplaySurfaceID? surfaceID) + private IDisplaySurface GetRelevantSurface(DisplaySurfaceID? surfaceID) { var nnID = surfaceID ?? _usingSurfaceID ?? throw new Exception(); void ThisIsTheLuaAutolockHack() diff --git a/src/BizHawk.Client.Common/DisplayManager/DisplaySurface.cs b/src/BizHawk.Client.Common/DisplayManager/DisplaySurface.cs index 14a3d506f1..30befb7933 100644 --- a/src/BizHawk.Client.Common/DisplayManager/DisplaySurface.cs +++ b/src/BizHawk.Client.Common/DisplayManager/DisplaySurface.cs @@ -1,4 +1,3 @@ -using System; using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; @@ -10,7 +9,7 @@ namespace BizHawk.Client.Common /// This is a wrapper for a Bitmap, basically, which can also be a int[]. /// It should be phased out, in favor of BitmapBuffer and Texture2d's /// - public unsafe class DisplaySurface : IDisposable + public unsafe class DisplaySurface : IDisplaySurface { private Bitmap _bmp; private BitmapData _bmpData; @@ -28,9 +27,6 @@ namespace BizHawk.Client.Common return _bmp; } - /// - /// returns a Graphics object used to render to this surface. be sure to dispose it! - /// public Graphics GetGraphics() { ToBitmap(); diff --git a/src/BizHawk.Client.Common/DisplayManager/IDisplayManagerForApi.cs b/src/BizHawk.Client.Common/DisplayManager/IDisplayManagerForApi.cs index 7334dcafc5..fb21ab02db 100644 --- a/src/BizHawk.Client.Common/DisplayManager/IDisplayManagerForApi.cs +++ b/src/BizHawk.Client.Common/DisplayManager/IDisplayManagerForApi.cs @@ -11,10 +11,10 @@ namespace BizHawk.Client.Common /// locks the surface with ID /// already locked, or unknown surface - DisplaySurface LockApiHawkSurface(DisplaySurfaceID surfaceID, bool clear = true); + IDisplaySurface LockApiHawkSurface(DisplaySurfaceID surfaceID, bool clear = true); /// unlocks the given , which must be a locked surface produced by /// already unlocked - void UnlockApiHawkSurface(DisplaySurface surface); + void UnlockApiHawkSurface(IDisplaySurface surface); } } diff --git a/src/BizHawk.Client.Common/DisplayManager/IDisplaySurface.cs b/src/BizHawk.Client.Common/DisplayManager/IDisplaySurface.cs new file mode 100644 index 0000000000..ccbb494748 --- /dev/null +++ b/src/BizHawk.Client.Common/DisplayManager/IDisplaySurface.cs @@ -0,0 +1,19 @@ +using System; +using System.Drawing; + +namespace BizHawk.Client.Common +{ + public interface IDisplaySurface : IDisposable + { + int Height { get; } + + int Width { get; } + + void Clear(); + + /// a used to render to this surface; be sure to dispose it! + Graphics GetGraphics(); + + Bitmap PeekBitmap(); + } +} diff --git a/src/BizHawk.Client.Common/DisplayManager/TextureFrugalizer.cs b/src/BizHawk.Client.Common/DisplayManager/TextureFrugalizer.cs index 5f676074a5..a084d8f506 100644 --- a/src/BizHawk.Client.Common/DisplayManager/TextureFrugalizer.cs +++ b/src/BizHawk.Client.Common/DisplayManager/TextureFrugalizer.cs @@ -34,7 +34,7 @@ namespace BizHawk.Client.Common private readonly IGL _gl; private List _currentTextures; - public Texture2d Get(DisplaySurface ds) + public Texture2d Get(IDisplaySurface ds) { using var bb = new BitmapBuffer(ds.PeekBitmap(), new BitmapLoadOptions()); return Get(bb); diff --git a/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs b/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs index ae1cecaeae..ec27a6451b 100644 --- a/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs +++ b/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs @@ -1097,24 +1097,24 @@ namespace BizHawk.Client.EmuHawk private bool? _lastVsyncSetting; private GraphicsControl _lastVsyncSettingGraphicsControl; - private readonly Dictionary _apiHawkIDToSurface = new(); + private readonly Dictionary _apiHawkIDToSurface = new(); - /// Can't this just be a field/prop of ? --yoshi - private readonly Dictionary _apiHawkSurfaceToID = new(); + /// Can't this just be a prop of ? --yoshi + private readonly Dictionary _apiHawkSurfaceToID = new(); private readonly Dictionary _apiHawkSurfaceSets = new(); /// /// Peeks a locked lua surface, or returns null if it isn't locked /// - public DisplaySurface PeekApiHawkLockedSurface(DisplaySurfaceID surfaceID) + public IDisplaySurface PeekApiHawkLockedSurface(DisplaySurfaceID surfaceID) { if (_apiHawkIDToSurface.ContainsKey(surfaceID)) return _apiHawkIDToSurface[surfaceID]; return null; } - public DisplaySurface LockApiHawkSurface(DisplaySurfaceID surfaceID, bool clear) + public IDisplaySurface LockApiHawkSurface(DisplaySurfaceID surfaceID, bool clear) { if (_apiHawkIDToSurface.ContainsKey(surfaceID)) { @@ -1141,7 +1141,7 @@ namespace BizHawk.Client.EmuHawk _ => throw new ArgumentException(message: "not a valid enum member", paramName: nameof(surfaceID)) }; - DisplaySurface ret = sdss.AllocateSurface(width, height, clear); + IDisplaySurface ret = sdss.AllocateSurface(width, height, clear); _apiHawkIDToSurface[surfaceID] = ret; _apiHawkSurfaceToID[ret] = surfaceID; return ret; @@ -1167,19 +1167,20 @@ namespace BizHawk.Client.EmuHawk } } - /// unlocks this DisplaySurface which had better have been locked as a lua surface + /// unlocks this IDisplaySurface which had better have been locked as a lua surface /// already unlocked - public void UnlockApiHawkSurface(DisplaySurface surface) + public void UnlockApiHawkSurface(IDisplaySurface surface) { - if (!_apiHawkSurfaceToID.ContainsKey(surface)) + if (surface is not DisplaySurface dispSurfaceImpl) throw new ArgumentException("o noes", nameof(surface)); + if (!_apiHawkSurfaceToID.ContainsKey(dispSurfaceImpl)) { throw new InvalidOperationException("Surface was not locked as a lua surface"); } - var surfaceID = _apiHawkSurfaceToID[surface]; - _apiHawkSurfaceToID.Remove(surface); + var surfaceID = _apiHawkSurfaceToID[dispSurfaceImpl]; + _apiHawkSurfaceToID.Remove(dispSurfaceImpl); _apiHawkIDToSurface.Remove(surfaceID); - _apiHawkSurfaceSets[surfaceID].SetPending(surface); + _apiHawkSurfaceSets[surfaceID].SetPending(dispSurfaceImpl); } // helper classes: