VKRenderer.cs 2.3 KB

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