|
|
@ -5,7 +5,7 @@ using Avalonia.Win32.Interop; |
|
|
|
|
|
|
|
|
namespace Avalonia.Win32 |
|
|
namespace Avalonia.Win32 |
|
|
{ |
|
|
{ |
|
|
class FramebufferManager : IFramebufferPlatformSurface |
|
|
class FramebufferManager : IFramebufferPlatformSurface, IDisposable |
|
|
{ |
|
|
{ |
|
|
private readonly IntPtr _hwnd; |
|
|
private readonly IntPtr _hwnd; |
|
|
private WindowFramebuffer _fb; |
|
|
private WindowFramebuffer _fb; |
|
|
@ -17,17 +17,25 @@ namespace Avalonia.Win32 |
|
|
|
|
|
|
|
|
public ILockedFramebuffer Lock() |
|
|
public ILockedFramebuffer Lock() |
|
|
{ |
|
|
{ |
|
|
UnmanagedMethods.RECT rc; |
|
|
UnmanagedMethods.GetClientRect(_hwnd, out var rc); |
|
|
UnmanagedMethods.GetClientRect(_hwnd, out rc); |
|
|
|
|
|
var width = rc.right - rc.left; |
|
|
var width = Math.Max(1, rc.right - rc.left); |
|
|
var height = rc.bottom - rc.top; |
|
|
var height = Math.Max(1, rc.bottom - rc.top); |
|
|
if ((_fb == null || _fb.Size.Width != width || _fb.Size.Height != height) && width > 0 && height > 0) |
|
|
|
|
|
|
|
|
if ((_fb == null || _fb.Size.Width != width || _fb.Size.Height != height)) |
|
|
{ |
|
|
{ |
|
|
_fb?.Deallocate(); |
|
|
_fb?.Deallocate(); |
|
|
_fb = null; |
|
|
_fb = null; |
|
|
_fb = new WindowFramebuffer(_hwnd, new PixelSize(width, height)); |
|
|
_fb = new WindowFramebuffer(_hwnd, new PixelSize(width, height)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return _fb; |
|
|
return _fb; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|
|
{ |
|
|
|
|
|
_fb?.Deallocate(); |
|
|
|
|
|
_fb = null; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|