VulkanEmbeddedWindow.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Avalonia.Platform;
  2. using Silk.NET.Vulkan;
  3. using SPB.Graphics.Vulkan;
  4. using SPB.Platform.GLX;
  5. using SPB.Platform.Metal;
  6. using SPB.Platform.Win32;
  7. using SPB.Platform.X11;
  8. using SPB.Windowing;
  9. using System;
  10. using System.Runtime.Versioning;
  11. namespace Ryujinx.Ava.UI.Helpers
  12. {
  13. public class VulkanEmbeddedWindow : EmbeddedWindow
  14. {
  15. private NativeWindowBase _window;
  16. [SupportedOSPlatform("linux")]
  17. protected override IPlatformHandle CreateLinux(IPlatformHandle parent)
  18. {
  19. X11Window = new GLXWindow(new NativeHandle(X11.DefaultDisplay), new NativeHandle(parent.Handle));
  20. WindowHandle = X11Window.WindowHandle.RawHandle;
  21. X11Display = X11Window.DisplayHandle.RawHandle;
  22. X11Window.Hide();
  23. return new PlatformHandle(WindowHandle, "X11");
  24. }
  25. public SurfaceKHR CreateSurface(Instance instance)
  26. {
  27. if (OperatingSystem.IsWindows())
  28. {
  29. _window = new SimpleWin32Window(new NativeHandle(WindowHandle));
  30. }
  31. else if (OperatingSystem.IsLinux())
  32. {
  33. _window = new SimpleX11Window(new NativeHandle(X11Display), new NativeHandle(WindowHandle));
  34. }
  35. else if (OperatingSystem.IsMacOS())
  36. {
  37. _window = new SimpleMetalWindow(new NativeHandle(NsView), new NativeHandle(MetalLayer));
  38. }
  39. else
  40. {
  41. throw new PlatformNotSupportedException();
  42. }
  43. return new SurfaceKHR((ulong?)VulkanHelper.CreateWindowSurface(instance.Handle, _window));
  44. }
  45. }
  46. }