Skip to content

Commit

Permalink
Disable WPF hardware acceleration when running dnSpy under Wine
Browse files Browse the repository at this point in the history
  • Loading branch information
ElektroKill committed Aug 7, 2024
1 parent 7ce4d52 commit f20c005
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions dnSpy/dnSpy/MainApp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public App(bool readSettings, Stopwatch startupStopwatch) {
ResourceHelper.SetResourceManagerTokenCache(resourceManagerTokenCacheImpl);
AppDirectories.SetSettingsFilename(args.SettingsFilename);

WineFixes.Initialize();
AddAppContextFixes();
InstallExceptionHandlers();
InitializeComponent();
Expand Down
32 changes: 32 additions & 0 deletions dnSpy/dnSpy/MainApp/WineFixes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Windows.Media;

namespace dnSpy.MainApp {
/// <summary>
/// Applies fixes and compatibility workarounds for running on Wine.
/// </summary>
static class WineFixes {
public static void Initialize() {
if (!IsRunningOnWine())
return;

// Disable WPF hardware acceleration on Wine
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
}

static bool IsRunningOnWine() {
var ntdll = GetModuleHandle("ntdll.dll");
if (ntdll == IntPtr.Zero)
return false;
return GetProcAddress(ntdll, "wine_get_version") != IntPtr.Zero;
}

[DllImport("kernel32", SetLastError = true)]
static extern IntPtr GetModuleHandle(string lpModuleName);

[DllImport("kernel32", SetLastError = true)]
static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
}
}

0 comments on commit f20c005

Please sign in to comment.