VulkanEmbeddedWindow.cs 1.6 KB

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