RendererWidgetBase.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. using ARMeilleure.Translation;
  2. using ARMeilleure.Translation.PTC;
  3. using Gdk;
  4. using Gtk;
  5. using Ryujinx.Common;
  6. using Ryujinx.Common.Configuration;
  7. using Ryujinx.Common.Logging;
  8. using Ryujinx.Ui.Common.Configuration;
  9. using Ryujinx.Graphics.Gpu;
  10. using Ryujinx.Graphics.GAL;
  11. using Ryujinx.Graphics.GAL.Multithreading;
  12. using Ryujinx.Input;
  13. using Ryujinx.Input.GTK3;
  14. using Ryujinx.Input.HLE;
  15. using Ryujinx.Ui.Widgets;
  16. using SixLabors.ImageSharp;
  17. using SixLabors.ImageSharp.Formats.Png;
  18. using SixLabors.ImageSharp.PixelFormats;
  19. using SixLabors.ImageSharp.Processing;
  20. using System;
  21. using System.Diagnostics;
  22. using System.IO;
  23. using System.Threading;
  24. using System.Threading.Tasks;
  25. namespace Ryujinx.Ui
  26. {
  27. using Image = SixLabors.ImageSharp.Image;
  28. using Key = Input.Key;
  29. using Switch = HLE.Switch;
  30. public abstract class RendererWidgetBase : DrawingArea
  31. {
  32. private const int SwitchPanelWidth = 1280;
  33. private const int SwitchPanelHeight = 720;
  34. private const int TargetFps = 60;
  35. private const float MaxResolutionScale = 4.0f; // Max resolution hotkeys can scale to before wrapping.
  36. public ManualResetEvent WaitEvent { get; set; }
  37. public NpadManager NpadManager { get; }
  38. public TouchScreenManager TouchScreenManager { get; }
  39. public Switch Device { get; private set; }
  40. public IRenderer Renderer { get; private set; }
  41. public bool ScreenshotRequested { get; set; }
  42. protected int WindowWidth { get; private set; }
  43. protected int WindowHeight { get; private set; }
  44. public static event EventHandler<StatusUpdatedEventArgs> StatusUpdatedEvent;
  45. private bool _isActive;
  46. private bool _isStopped;
  47. private bool _toggleFullscreen;
  48. private bool _toggleDockedMode;
  49. private readonly long _ticksPerFrame;
  50. private long _ticks = 0;
  51. private readonly Stopwatch _chrono;
  52. private KeyboardHotkeyState _prevHotkeyState;
  53. private readonly ManualResetEvent _exitEvent;
  54. private readonly CancellationTokenSource _gpuCancellationTokenSource;
  55. // Hide Cursor
  56. const int CursorHideIdleTime = 8; // seconds
  57. private static readonly Cursor _invisibleCursor = new Cursor(Display.Default, CursorType.BlankCursor);
  58. private long _lastCursorMoveTime;
  59. private bool _hideCursorOnIdle;
  60. private InputManager _inputManager;
  61. private IKeyboard _keyboardInterface;
  62. private GraphicsDebugLevel _glLogLevel;
  63. private string _gpuBackendName;
  64. private string _gpuVendorName;
  65. private bool _isMouseInClient;
  66. public RendererWidgetBase(InputManager inputManager, GraphicsDebugLevel glLogLevel)
  67. {
  68. var mouseDriver = new GTK3MouseDriver(this);
  69. _inputManager = inputManager;
  70. _inputManager.SetMouseDriver(mouseDriver);
  71. NpadManager = _inputManager.CreateNpadManager();
  72. TouchScreenManager = _inputManager.CreateTouchScreenManager();
  73. _keyboardInterface = (IKeyboard)_inputManager.KeyboardDriver.GetGamepad("0");
  74. WaitEvent = new ManualResetEvent(false);
  75. _glLogLevel = glLogLevel;
  76. Destroyed += Renderer_Destroyed;
  77. _chrono = new Stopwatch();
  78. _ticksPerFrame = Stopwatch.Frequency / TargetFps;
  79. AddEvents((int)(EventMask.ButtonPressMask
  80. | EventMask.ButtonReleaseMask
  81. | EventMask.PointerMotionMask
  82. | EventMask.ScrollMask
  83. | EventMask.EnterNotifyMask
  84. | EventMask.LeaveNotifyMask
  85. | EventMask.KeyPressMask
  86. | EventMask.KeyReleaseMask));
  87. _exitEvent = new ManualResetEvent(false);
  88. _gpuCancellationTokenSource = new CancellationTokenSource();
  89. _hideCursorOnIdle = ConfigurationState.Instance.HideCursorOnIdle;
  90. _lastCursorMoveTime = Stopwatch.GetTimestamp();
  91. ConfigurationState.Instance.HideCursorOnIdle.Event += HideCursorStateChanged;
  92. }
  93. public abstract void InitializeRenderer();
  94. public abstract void SwapBuffers(object image);
  95. protected abstract string GetGpuBackendName();
  96. private string GetGpuVendorName()
  97. {
  98. return Renderer.GetHardwareInfo().GpuVendor;
  99. }
  100. private void HideCursorStateChanged(object sender, ReactiveEventArgs<bool> state)
  101. {
  102. Gtk.Application.Invoke(delegate
  103. {
  104. _hideCursorOnIdle = state.NewValue;
  105. if (_hideCursorOnIdle)
  106. {
  107. _lastCursorMoveTime = Stopwatch.GetTimestamp();
  108. }
  109. else
  110. {
  111. Window.Cursor = null;
  112. }
  113. });
  114. }
  115. private void Renderer_Destroyed(object sender, EventArgs e)
  116. {
  117. ConfigurationState.Instance.HideCursorOnIdle.Event -= HideCursorStateChanged;
  118. NpadManager.Dispose();
  119. Dispose();
  120. }
  121. protected override bool OnMotionNotifyEvent(EventMotion evnt)
  122. {
  123. if (_hideCursorOnIdle)
  124. {
  125. _lastCursorMoveTime = Stopwatch.GetTimestamp();
  126. }
  127. if (ConfigurationState.Instance.Hid.EnableMouse)
  128. {
  129. Window.Cursor = _invisibleCursor;
  130. }
  131. _isMouseInClient = true;
  132. return false;
  133. }
  134. protected override bool OnEnterNotifyEvent(EventCrossing evnt)
  135. {
  136. Window.Cursor = ConfigurationState.Instance.Hid.EnableMouse ? _invisibleCursor : null;
  137. _isMouseInClient = true;
  138. return base.OnEnterNotifyEvent(evnt);
  139. }
  140. protected override bool OnLeaveNotifyEvent(EventCrossing evnt)
  141. {
  142. Window.Cursor = null;
  143. _isMouseInClient = false;
  144. return base.OnLeaveNotifyEvent(evnt);
  145. }
  146. protected override void OnGetPreferredHeight(out int minimumHeight, out int naturalHeight)
  147. {
  148. Gdk.Monitor monitor = Display.GetMonitorAtWindow(Window);
  149. // If the monitor is at least 1080p, use the Switch panel size as minimal size.
  150. if (monitor.Geometry.Height >= 1080)
  151. {
  152. minimumHeight = SwitchPanelHeight;
  153. }
  154. // Otherwise, we default minimal size to 480p 16:9.
  155. else
  156. {
  157. minimumHeight = 480;
  158. }
  159. naturalHeight = minimumHeight;
  160. }
  161. protected override void OnGetPreferredWidth(out int minimumWidth, out int naturalWidth)
  162. {
  163. Gdk.Monitor monitor = Display.GetMonitorAtWindow(Window);
  164. // If the monitor is at least 1080p, use the Switch panel size as minimal size.
  165. if (monitor.Geometry.Height >= 1080)
  166. {
  167. minimumWidth = SwitchPanelWidth;
  168. }
  169. // Otherwise, we default minimal size to 480p 16:9.
  170. else
  171. {
  172. minimumWidth = 854;
  173. }
  174. naturalWidth = minimumWidth;
  175. }
  176. protected override bool OnConfigureEvent(EventConfigure evnt)
  177. {
  178. bool result = base.OnConfigureEvent(evnt);
  179. Gdk.Monitor monitor = Display.GetMonitorAtWindow(Window);
  180. WindowWidth = evnt.Width * monitor.ScaleFactor;
  181. WindowHeight = evnt.Height * monitor.ScaleFactor;
  182. Renderer?.Window?.SetSize(WindowWidth, WindowHeight);
  183. return result;
  184. }
  185. private void HandleScreenState(KeyboardStateSnapshot keyboard)
  186. {
  187. bool toggleFullscreen = keyboard.IsPressed(Key.F11)
  188. || ((keyboard.IsPressed(Key.AltLeft)
  189. || keyboard.IsPressed(Key.AltRight))
  190. && keyboard.IsPressed(Key.Enter))
  191. || keyboard.IsPressed(Key.Escape);
  192. bool fullScreenToggled = ParentWindow.State.HasFlag(Gdk.WindowState.Fullscreen);
  193. if (toggleFullscreen != _toggleFullscreen)
  194. {
  195. if (toggleFullscreen)
  196. {
  197. if (fullScreenToggled)
  198. {
  199. ParentWindow.Unfullscreen();
  200. (Toplevel as MainWindow)?.ToggleExtraWidgets(true);
  201. }
  202. else
  203. {
  204. if (keyboard.IsPressed(Key.Escape))
  205. {
  206. if (!ConfigurationState.Instance.ShowConfirmExit || GtkDialog.CreateExitDialog())
  207. {
  208. Exit();
  209. }
  210. }
  211. else
  212. {
  213. ParentWindow.Fullscreen();
  214. (Toplevel as MainWindow)?.ToggleExtraWidgets(false);
  215. }
  216. }
  217. }
  218. }
  219. _toggleFullscreen = toggleFullscreen;
  220. bool toggleDockedMode = keyboard.IsPressed(Key.F9);
  221. if (toggleDockedMode != _toggleDockedMode)
  222. {
  223. if (toggleDockedMode)
  224. {
  225. ConfigurationState.Instance.System.EnableDockedMode.Value =
  226. !ConfigurationState.Instance.System.EnableDockedMode.Value;
  227. }
  228. }
  229. _toggleDockedMode = toggleDockedMode;
  230. if (_hideCursorOnIdle && !ConfigurationState.Instance.Hid.EnableMouse)
  231. {
  232. long cursorMoveDelta = Stopwatch.GetTimestamp() - _lastCursorMoveTime;
  233. Window.Cursor = (cursorMoveDelta >= CursorHideIdleTime * Stopwatch.Frequency) ? _invisibleCursor : null;
  234. }
  235. if(ConfigurationState.Instance.Hid.EnableMouse && _isMouseInClient)
  236. {
  237. Window.Cursor = _invisibleCursor;
  238. }
  239. }
  240. public void Initialize(Switch device)
  241. {
  242. Device = device;
  243. IRenderer renderer = Device.Gpu.Renderer;
  244. if (renderer is ThreadedRenderer tr)
  245. {
  246. renderer = tr.BaseRenderer;
  247. }
  248. Renderer = renderer;
  249. Renderer?.Window?.SetSize(WindowWidth, WindowHeight);
  250. if (Renderer != null)
  251. {
  252. Renderer.ScreenCaptured += Renderer_ScreenCaptured;
  253. }
  254. NpadManager.Initialize(device, ConfigurationState.Instance.Hid.InputConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.Hid.EnableMouse);
  255. TouchScreenManager.Initialize(device);
  256. }
  257. private unsafe void Renderer_ScreenCaptured(object sender, ScreenCaptureImageInfo e)
  258. {
  259. if (e.Data.Length > 0 && e.Height > 0 && e.Width > 0)
  260. {
  261. Task.Run(() =>
  262. {
  263. lock (this)
  264. {
  265. var currentTime = DateTime.Now;
  266. string filename = $"ryujinx_capture_{currentTime.Year}-{currentTime.Month:D2}-{currentTime.Day:D2}_{currentTime.Hour:D2}-{currentTime.Minute:D2}-{currentTime.Second:D2}.png";
  267. string directory = AppDataManager.Mode switch
  268. {
  269. AppDataManager.LaunchMode.Portable => System.IO.Path.Combine(AppDataManager.BaseDirPath, "screenshots"),
  270. _ => System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures), "Ryujinx")
  271. };
  272. string path = System.IO.Path.Combine(directory, filename);
  273. try
  274. {
  275. Directory.CreateDirectory(directory);
  276. }
  277. catch (Exception ex)
  278. {
  279. Logger.Error?.Print(LogClass.Application, $"Failed to create directory at path {directory}. Error : {ex.GetType().Name}", "Screenshot");
  280. return;
  281. }
  282. Image image = e.IsBgra ? Image.LoadPixelData<Bgra32>(e.Data, e.Width, e.Height)
  283. : Image.LoadPixelData<Rgba32>(e.Data, e.Width, e.Height);
  284. if (e.FlipX)
  285. {
  286. image.Mutate(x => x.Flip(FlipMode.Horizontal));
  287. }
  288. if (e.FlipY)
  289. {
  290. image.Mutate(x => x.Flip(FlipMode.Vertical));
  291. }
  292. image.SaveAsPng(path, new PngEncoder()
  293. {
  294. ColorType = PngColorType.Rgb
  295. });
  296. image.Dispose();
  297. Logger.Notice.Print(LogClass.Application, $"Screenshot saved to {path}", "Screenshot");
  298. }
  299. });
  300. }
  301. else
  302. {
  303. Logger.Error?.Print(LogClass.Application, $"Screenshot is empty. Size : {e.Data.Length} bytes. Resolution : {e.Width}x{e.Height}", "Screenshot");
  304. }
  305. }
  306. public void Render()
  307. {
  308. Gtk.Window parent = Toplevel as Gtk.Window;
  309. parent.Present();
  310. InitializeRenderer();
  311. Device.Gpu.Renderer.Initialize(_glLogLevel);
  312. _gpuBackendName = GetGpuBackendName();
  313. _gpuVendorName = GetGpuVendorName();
  314. Device.Gpu.Renderer.RunLoop(() =>
  315. {
  316. Device.Gpu.SetGpuThread();
  317. Device.Gpu.InitializeShaderCache(_gpuCancellationTokenSource.Token);
  318. Translator.IsReadyForTranslation.Set();
  319. Renderer.Window.ChangeVSyncMode(Device.EnableDeviceVsync);
  320. (Toplevel as MainWindow)?.ActivatePauseMenu();
  321. while (_isActive)
  322. {
  323. if (_isStopped)
  324. {
  325. return;
  326. }
  327. _ticks += _chrono.ElapsedTicks;
  328. _chrono.Restart();
  329. if (Device.WaitFifo())
  330. {
  331. Device.Statistics.RecordFifoStart();
  332. Device.ProcessFrame();
  333. Device.Statistics.RecordFifoEnd();
  334. }
  335. while (Device.ConsumeFrameAvailable())
  336. {
  337. Device.PresentFrame((texture) => { SwapBuffers(texture);});
  338. }
  339. if (_ticks >= _ticksPerFrame)
  340. {
  341. string dockedMode = ConfigurationState.Instance.System.EnableDockedMode ? "Docked" : "Handheld";
  342. float scale = Graphics.Gpu.GraphicsConfig.ResScale;
  343. if (scale != 1)
  344. {
  345. dockedMode += $" ({scale}x)";
  346. }
  347. StatusUpdatedEvent?.Invoke(this, new StatusUpdatedEventArgs(
  348. Device.EnableDeviceVsync,
  349. Device.GetVolume(),
  350. _gpuBackendName,
  351. dockedMode,
  352. ConfigurationState.Instance.Graphics.AspectRatio.Value.ToText(),
  353. $"Game: {Device.Statistics.GetGameFrameRate():00.00} FPS ({Device.Statistics.GetGameFrameTime():00.00} ms)",
  354. $"FIFO: {Device.Statistics.GetFifoPercent():0.00} %",
  355. $"GPU: {_gpuVendorName}"));
  356. _ticks = Math.Min(_ticks - _ticksPerFrame, _ticksPerFrame);
  357. }
  358. }
  359. });
  360. }
  361. public void Start()
  362. {
  363. _chrono.Restart();
  364. _isActive = true;
  365. Gtk.Window parent = Toplevel as Gtk.Window;
  366. Application.Invoke(delegate
  367. {
  368. parent.Present();
  369. string titleNameSection = string.IsNullOrWhiteSpace(Device.Application.TitleName) ? string.Empty
  370. : $" - {Device.Application.TitleName}";
  371. string titleVersionSection = string.IsNullOrWhiteSpace(Device.Application.DisplayVersion) ? string.Empty
  372. : $" v{Device.Application.DisplayVersion}";
  373. string titleIdSection = string.IsNullOrWhiteSpace(Device.Application.TitleIdText) ? string.Empty
  374. : $" ({Device.Application.TitleIdText.ToUpper()})";
  375. string titleArchSection = Device.Application.TitleIs64Bit ? " (64-bit)" : " (32-bit)";
  376. parent.Title = $"Ryujinx {Program.Version}{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}";
  377. });
  378. Thread renderLoopThread = new Thread(Render)
  379. {
  380. Name = "GUI.RenderLoop"
  381. };
  382. renderLoopThread.Start();
  383. Thread nvStutterWorkaround = null;
  384. if (Renderer is Graphics.OpenGL.OpenGLRenderer)
  385. {
  386. nvStutterWorkaround = new Thread(NVStutterWorkaround)
  387. {
  388. Name = "GUI.NVStutterWorkaround"
  389. };
  390. nvStutterWorkaround.Start();
  391. }
  392. MainLoop();
  393. renderLoopThread.Join();
  394. nvStutterWorkaround?.Join();
  395. Exit();
  396. }
  397. public void Exit()
  398. {
  399. TouchScreenManager?.Dispose();
  400. NpadManager?.Dispose();
  401. if (_isStopped)
  402. {
  403. return;
  404. }
  405. _gpuCancellationTokenSource.Cancel();
  406. _isStopped = true;
  407. _isActive = false;
  408. _exitEvent.WaitOne();
  409. _exitEvent.Dispose();
  410. }
  411. private void NVStutterWorkaround()
  412. {
  413. while (_isActive)
  414. {
  415. // When NVIDIA Threaded Optimization is on, the driver will snapshot all threads in the system whenever the application creates any new ones.
  416. // The ThreadPool has something called a "GateThread" which terminates itself after some inactivity.
  417. // However, it immediately starts up again, since the rules regarding when to terminate and when to start differ.
  418. // This creates a new thread every second or so.
  419. // The main problem with this is that the thread snapshot can take 70ms, is on the OpenGL thread and will delay rendering any graphics.
  420. // This is a little over budget on a frame time of 16ms, so creates a large stutter.
  421. // The solution is to keep the ThreadPool active so that it never has a reason to terminate the GateThread.
  422. // TODO: This should be removed when the issue with the GateThread is resolved.
  423. ThreadPool.QueueUserWorkItem((state) => { });
  424. Thread.Sleep(300);
  425. }
  426. }
  427. public void MainLoop()
  428. {
  429. while (_isActive)
  430. {
  431. UpdateFrame();
  432. // Polling becomes expensive if it's not slept
  433. Thread.Sleep(1);
  434. }
  435. _exitEvent.Set();
  436. }
  437. private bool UpdateFrame()
  438. {
  439. if (!_isActive)
  440. {
  441. return true;
  442. }
  443. if (_isStopped)
  444. {
  445. return false;
  446. }
  447. if ((Toplevel as MainWindow).IsFocused)
  448. {
  449. Application.Invoke(delegate
  450. {
  451. KeyboardStateSnapshot keyboard = _keyboardInterface.GetKeyboardStateSnapshot();
  452. HandleScreenState(keyboard);
  453. if (keyboard.IsPressed(Key.Delete))
  454. {
  455. if (!ParentWindow.State.HasFlag(WindowState.Fullscreen))
  456. {
  457. Ptc.Continue();
  458. }
  459. }
  460. });
  461. }
  462. NpadManager.Update(ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat());
  463. if ((Toplevel as MainWindow).IsFocused)
  464. {
  465. KeyboardHotkeyState currentHotkeyState = GetHotkeyState();
  466. if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync) &&
  467. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync))
  468. {
  469. Device.EnableDeviceVsync = !Device.EnableDeviceVsync;
  470. }
  471. if ((currentHotkeyState.HasFlag(KeyboardHotkeyState.Screenshot) &&
  472. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.Screenshot)) || ScreenshotRequested)
  473. {
  474. ScreenshotRequested = false;
  475. Renderer.Screenshot();
  476. }
  477. if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ShowUi) &&
  478. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ShowUi))
  479. {
  480. (Toplevel as MainWindow).ToggleExtraWidgets(true);
  481. }
  482. if (currentHotkeyState.HasFlag(KeyboardHotkeyState.Pause) &&
  483. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.Pause))
  484. {
  485. (Toplevel as MainWindow)?.TogglePause();
  486. }
  487. if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ToggleMute) &&
  488. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ToggleMute))
  489. {
  490. if (Device.IsAudioMuted())
  491. {
  492. Device.SetVolume(ConfigurationState.Instance.System.AudioVolume);
  493. }
  494. else
  495. {
  496. Device.SetVolume(0);
  497. }
  498. }
  499. if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ResScaleUp) &&
  500. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ResScaleUp))
  501. {
  502. GraphicsConfig.ResScale = GraphicsConfig.ResScale % MaxResolutionScale + 1;
  503. }
  504. if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ResScaleDown) &&
  505. !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ResScaleDown))
  506. {
  507. GraphicsConfig.ResScale =
  508. (MaxResolutionScale + GraphicsConfig.ResScale - 2) % MaxResolutionScale + 1;
  509. }
  510. _prevHotkeyState = currentHotkeyState;
  511. }
  512. // Touchscreen
  513. bool hasTouch = false;
  514. // Get screen touch position
  515. if ((Toplevel as MainWindow).IsFocused && !ConfigurationState.Instance.Hid.EnableMouse)
  516. {
  517. hasTouch = TouchScreenManager.Update(true, (_inputManager.MouseDriver as GTK3MouseDriver).IsButtonPressed(MouseButton.Button1), ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat());
  518. }
  519. if (!hasTouch)
  520. {
  521. TouchScreenManager.Update(false);
  522. }
  523. Device.Hid.DebugPad.Update();
  524. return true;
  525. }
  526. [Flags]
  527. private enum KeyboardHotkeyState
  528. {
  529. None = 0,
  530. ToggleVSync = 1 << 0,
  531. Screenshot = 1 << 1,
  532. ShowUi = 1 << 2,
  533. Pause = 1 << 3,
  534. ToggleMute = 1 << 4,
  535. ResScaleUp = 1 << 5,
  536. ResScaleDown = 1 << 6
  537. }
  538. private KeyboardHotkeyState GetHotkeyState()
  539. {
  540. KeyboardHotkeyState state = KeyboardHotkeyState.None;
  541. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ToggleVsync))
  542. {
  543. state |= KeyboardHotkeyState.ToggleVSync;
  544. }
  545. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.Screenshot))
  546. {
  547. state |= KeyboardHotkeyState.Screenshot;
  548. }
  549. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ShowUi))
  550. {
  551. state |= KeyboardHotkeyState.ShowUi;
  552. }
  553. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.Pause))
  554. {
  555. state |= KeyboardHotkeyState.Pause;
  556. }
  557. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ToggleMute))
  558. {
  559. state |= KeyboardHotkeyState.ToggleMute;
  560. }
  561. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ResScaleUp))
  562. {
  563. state |= KeyboardHotkeyState.ResScaleUp;
  564. }
  565. if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ResScaleDown))
  566. {
  567. state |= KeyboardHotkeyState.ResScaleDown;
  568. }
  569. return state;
  570. }
  571. }
  572. }