SDL2Driver: Invoke dispatcher on main thread (#3818)

This commit is contained in:
merry 2022-12-02 13:37:22 +00:00 committed by GitHub
parent d9053bbe37
commit 204c031fef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 21 deletions

View file

@ -8,6 +8,7 @@ using Ryujinx.Common.Logging;
using Ryujinx.Common.System; using Ryujinx.Common.System;
using Ryujinx.Common.SystemInfo; using Ryujinx.Common.SystemInfo;
using Ryujinx.Modules; using Ryujinx.Modules;
using Ryujinx.SDL2.Common;
using Ryujinx.Ui.Common; using Ryujinx.Ui.Common;
using Ryujinx.Ui.Common.Configuration; using Ryujinx.Ui.Common.Configuration;
using Ryujinx.Ui.Common.Helper; using Ryujinx.Ui.Common.Helper;
@ -94,6 +95,9 @@ namespace Ryujinx.Ava
// Initialize Discord integration. // Initialize Discord integration.
DiscordIntegrationModule.Initialize(); DiscordIntegrationModule.Initialize();
// Initialize SDL2 driver
SDL2Driver.MainThreadDispatcher = action => Dispatcher.UIThread.InvokeAsync(action, DispatcherPriority.Input);
ReloadConfig(); ReloadConfig();
ForceDpiAware.Windows(); ForceDpiAware.Windows();

View file

@ -638,16 +638,7 @@ namespace Ryujinx.Headless.SDL2
Translator.IsReadyForTranslation.Reset(); Translator.IsReadyForTranslation.Reset();
Thread windowThread = new Thread(() => ExecutionEntrypoint();
{
ExecutionEntrypoint();
})
{
Name = "GUI.WindowThread"
};
windowThread.Start();
windowThread.Join();
return true; return true;
} }

View file

@ -168,14 +168,6 @@ namespace Ryujinx.Headless.SDL2
public void Render() public void Render()
{ {
InitializeWindowRenderer();
Device.Gpu.Renderer.Initialize(_glLogLevel);
InitializeRenderer();
_gpuVendorName = GetGpuVendorName();
Device.Gpu.Renderer.RunLoop(() => Device.Gpu.Renderer.RunLoop(() =>
{ {
Device.Gpu.SetGpuThread(); Device.Gpu.SetGpuThread();
@ -323,6 +315,14 @@ namespace Ryujinx.Headless.SDL2
InitializeWindow(); InitializeWindow();
InitializeWindowRenderer();
Device.Gpu.Renderer.Initialize(_glLogLevel);
InitializeRenderer();
_gpuVendorName = GetGpuVendorName();
Thread renderLoopThread = new Thread(Render) Thread renderLoopThread = new Thread(Render)
{ {
Name = "GUI.RenderLoop" Name = "GUI.RenderLoop"

View file

@ -28,6 +28,8 @@ namespace Ryujinx.SDL2.Common
} }
} }
public static Action<Action> MainThreadDispatcher { get; set; }
private const uint SdlInitFlags = SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_VIDEO; private const uint SdlInitFlags = SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_VIDEO;
private bool _isRunning; private bool _isRunning;
@ -154,10 +156,13 @@ namespace Ryujinx.SDL2.Common
while (_isRunning) while (_isRunning)
{ {
while (SDL_PollEvent(out SDL_Event evnt) != 0) MainThreadDispatcher?.Invoke(() =>
{ {
HandleSDLEvent(ref evnt); while (SDL_PollEvent(out SDL_Event evnt) != 0)
} {
HandleSDLEvent(ref evnt);
}
});
waitHandle.Wait(WaitTimeMs); waitHandle.Wait(WaitTimeMs);
} }

View file

@ -7,6 +7,7 @@ using Ryujinx.Common.Logging;
using Ryujinx.Common.System; using Ryujinx.Common.System;
using Ryujinx.Common.SystemInfo; using Ryujinx.Common.SystemInfo;
using Ryujinx.Modules; using Ryujinx.Modules;
using Ryujinx.SDL2.Common;
using Ryujinx.Ui; using Ryujinx.Ui;
using Ryujinx.Ui.Common; using Ryujinx.Ui.Common;
using Ryujinx.Ui.Common.Configuration; using Ryujinx.Ui.Common.Configuration;
@ -111,6 +112,15 @@ namespace Ryujinx
// Initialize Discord integration. // Initialize Discord integration.
DiscordIntegrationModule.Initialize(); DiscordIntegrationModule.Initialize();
// Initialize SDL2 driver
SDL2Driver.MainThreadDispatcher = action =>
{
Gtk.Application.Invoke(delegate
{
action();
});
};
// Sets ImageSharp Jpeg Encoder Quality. // Sets ImageSharp Jpeg Encoder Quality.
SixLabors.ImageSharp.Configuration.Default.ImageFormatsManager.SetEncoder(JpegFormat.Instance, new JpegEncoder() SixLabors.ImageSharp.Configuration.Default.ImageFormatsManager.SetEncoder(JpegFormat.Instance, new JpegEncoder()
{ {