VulkanEmbeddedWindow.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.Win32;
  7. using SPB.Platform.X11;
  8. using SPB.Windowing;
  9. using System;
  10. using System.Runtime.Versioning;
  11. namespace Ryujinx.Ava.Ui
  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
  36. {
  37. throw new PlatformNotSupportedException();
  38. }
  39. return new SurfaceKHR((ulong?)VulkanHelper.CreateWindowSurface(instance.Handle, _window));
  40. }
  41. }
  42. }