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

View file

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

View file

@ -168,14 +168,6 @@ namespace Ryujinx.Headless.SDL2
public void Render()
{
InitializeWindowRenderer();
Device.Gpu.Renderer.Initialize(_glLogLevel);
InitializeRenderer();
_gpuVendorName = GetGpuVendorName();
Device.Gpu.Renderer.RunLoop(() =>
{
Device.Gpu.SetGpuThread();
@ -323,6 +315,14 @@ namespace Ryujinx.Headless.SDL2
InitializeWindow();
InitializeWindowRenderer();
Device.Gpu.Renderer.Initialize(_glLogLevel);
InitializeRenderer();
_gpuVendorName = GetGpuVendorName();
Thread renderLoopThread = new Thread(Render)
{
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 bool _isRunning;
@ -153,11 +155,14 @@ namespace Ryujinx.SDL2.Common
using ManualResetEventSlim waitHandle = new ManualResetEventSlim(false);
while (_isRunning)
{
MainThreadDispatcher?.Invoke(() =>
{
while (SDL_PollEvent(out SDL_Event evnt) != 0)
{
HandleSDLEvent(ref evnt);
}
});
waitHandle.Wait(WaitTimeMs);
}

View file

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