FramebufferManager.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using Avalonia.Controls.Platform.Surfaces;
  3. namespace Avalonia.Gtk
  4. {
  5. class FramebufferManager : IFramebufferPlatformSurface, IDisposable
  6. {
  7. private readonly WindowImplBase _window;
  8. private PixbufFramebuffer _fb;
  9. public FramebufferManager(WindowImplBase window)
  10. {
  11. _window = window;
  12. }
  13. public void Dispose()
  14. {
  15. _fb?.Deallocate();
  16. }
  17. public ILockedFramebuffer Lock()
  18. {
  19. if(_window.CurrentDrawable == null)
  20. throw new InvalidOperationException("Window is not in drawing state");
  21. var drawable = _window.CurrentDrawable;
  22. var width = (int) _window.ClientSize.Width;
  23. var height = (int) _window.ClientSize.Height;
  24. if (_fb == null || _fb.Width != width ||
  25. _fb.Height != height)
  26. {
  27. _fb?.Dispose();
  28. _fb = new PixbufFramebuffer(width, height);
  29. }
  30. _fb.SetDrawable(drawable);
  31. return _fb;
  32. }
  33. }
  34. }