VKRenderer.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Gdk;
  2. using Gtk;
  3. using Ryujinx.Common.Configuration;
  4. using Ryujinx.Input.HLE;
  5. using SPB.Graphics.Vulkan;
  6. using SPB.Platform.Win32;
  7. using SPB.Platform.X11;
  8. using SPB.Windowing;
  9. using System;
  10. using System.Runtime.InteropServices;
  11. namespace Ryujinx.Ui
  12. {
  13. public class VKRenderer : RendererWidgetBase
  14. {
  15. public NativeWindowBase NativeWindow { get; private set; }
  16. public VKRenderer(InputManager inputManager, GraphicsDebugLevel glLogLevel) : base(inputManager, glLogLevel) { }
  17. private NativeWindowBase RetrieveNativeWindow()
  18. {
  19. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
  20. {
  21. IntPtr windowHandle = gdk_win32_window_get_handle(Window.Handle);
  22. return new SimpleWin32Window(new NativeHandle(windowHandle));
  23. }
  24. else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
  25. {
  26. IntPtr displayHandle = gdk_x11_display_get_xdisplay(Display.Handle);
  27. IntPtr windowHandle = gdk_x11_window_get_xid(Window.Handle);
  28. return new SimpleX11Window(new NativeHandle(displayHandle), new NativeHandle(windowHandle));
  29. }
  30. throw new NotImplementedException();
  31. }
  32. [DllImport("libgdk-3-0.dll")]
  33. private static extern IntPtr gdk_win32_window_get_handle(IntPtr d);
  34. [DllImport("libgdk-3.so.0")]
  35. private static extern IntPtr gdk_x11_display_get_xdisplay(IntPtr gdkDisplay);
  36. [DllImport("libgdk-3.so.0")]
  37. private static extern IntPtr gdk_x11_window_get_xid(IntPtr gdkWindow);
  38. protected override bool OnConfigureEvent(EventConfigure evnt)
  39. {
  40. if (NativeWindow == null)
  41. {
  42. NativeWindow = RetrieveNativeWindow();
  43. WaitEvent.Set();
  44. }
  45. return base.OnConfigureEvent(evnt);
  46. }
  47. public unsafe IntPtr CreateWindowSurface(IntPtr instance)
  48. {
  49. return VulkanHelper.CreateWindowSurface(instance, NativeWindow);
  50. }
  51. public override void InitializeRenderer() { }
  52. public override void SwapBuffers() { }
  53. public override string GetGpuVendorName()
  54. {
  55. return "Vulkan (Unknown)";
  56. }
  57. protected override void Dispose(bool disposing)
  58. {
  59. Device.DisposeGpu();
  60. NpadManager.Dispose();
  61. }
  62. }
  63. }