FramebufferManager.cs 915 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using Avalonia.Controls.Platform.Surfaces;
  3. using Avalonia.Platform;
  4. using Avalonia.Win32.Interop;
  5. namespace Avalonia.Win32
  6. {
  7. class FramebufferManager : IFramebufferPlatformSurface
  8. {
  9. private readonly IntPtr _hwnd;
  10. private WindowFramebuffer _fb;
  11. public FramebufferManager(IntPtr hwnd)
  12. {
  13. _hwnd = hwnd;
  14. }
  15. public ILockedFramebuffer Lock()
  16. {
  17. UnmanagedMethods.GetClientRect(_hwnd, out var rc);
  18. var width = Math.Max(1, rc.right - rc.left);
  19. var height = Math.Max(1, rc.bottom - rc.top);
  20. if ((_fb == null || _fb.Size.Width != width || _fb.Size.Height != height))
  21. {
  22. _fb?.Deallocate();
  23. _fb = null;
  24. _fb = new WindowFramebuffer(_hwnd, new PixelSize(width, height));
  25. }
  26. return _fb;
  27. }
  28. }
  29. }