Skip to content

Commit 2eb8d74

Browse files
authored
Merge pull request #20617 from unoplatform/mergify/bp/release/stable/6.0/pr-20557
fix(linux): only init DpiBootstrap on Windows (backport #20557)
2 parents 6ddc81a + ea9bac3 commit 2eb8d74

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

src/SamplesApp/SamplesApp.Skia.Generic/Program.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,8 @@ private static void Run()
5656
global::Uno.Foundation.Extensibility.ApiExtensibility.Register<Microsoft.Web.WebView2.Core.CoreWebView2>(typeof(Microsoft.Web.WebView2.Core.INativeWebViewProvider), o => new global::Uno.UI.WebView.Skia.X11.X11NativeWebViewProvider(o));
5757
}
5858
})
59-
.UseX11(hostBuilder => hostBuilder.PreloadMediaPlayer(true));
60-
61-
if (OperatingSystem.IsWindows())
62-
{
63-
void Build()
64-
{
65-
// This is in a separate method to avoid loading the win32 uno runtime assembly
66-
// This assumes that the runtime loads dependencies when entering the method.
67-
68-
builder = builder
69-
.UseWin32(hostBuilder => hostBuilder.PreloadMediaPlayer(true));
70-
}
71-
72-
Build();
73-
}
74-
75-
builder = builder
59+
.UseX11(hostBuilder => hostBuilder.PreloadMediaPlayer(true))
60+
.UseWin32(hostBuilder => hostBuilder.PreloadMediaPlayer(true))
7661
.UseWindows()
7762
.UseLinuxFrameBuffer()
7863
.UseWindows(b => b

src/Uno.Foundation.Logging/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
[assembly: InternalsVisibleTo("Uno.UI.Runtime.Skia.MacOS")]
2525
[assembly: InternalsVisibleTo("Uno.UI.Runtime.Skia.Wpf")]
2626
[assembly: InternalsVisibleTo("Uno.UI.Runtime.Skia.Win32")]
27+
[assembly: InternalsVisibleTo("Uno.UI.Runtime.Skia.Win32.Support")]
2728
[assembly: InternalsVisibleTo("Uno.UI.Maps")]
2829
[assembly: InternalsVisibleTo("Uno.UI.Runtime.Skia.Tizen")]
2930
[assembly: InternalsVisibleTo("Uno.UI.Runtime.Skia.Linux.FrameBuffer")]

src/Uno.UI.Runtime.Skia.Win32/DpiBootstrap.cs renamed to src/Uno.UI.Runtime.Skia.Win32.Support/DpiBootstrap.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
using System.Runtime.CompilerServices;
1+
using System;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
24
using Windows.Win32;
5+
using Windows.Win32.Foundation;
6+
using Windows.Win32.System.Diagnostics.Debug;
37
using Windows.Win32.UI.HiDpi;
8+
using Uno.Foundation.Logging;
49

510
#pragma warning disable CA2255
611

@@ -31,6 +36,30 @@ internal static void Init()
3136
//
3237
// This call must be made BEFORE any window is initialized.
3338

34-
PInvoke.SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
39+
var success = PInvoke.SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
40+
if (!success) { typeof(DpiBootstrap).LogError()?.Error($"{nameof(PInvoke.AddClipboardFormatListener)} failed: {GetErrorMessage()}"); }
41+
}
42+
43+
private static string GetErrorMessage() => GetErrorMessage((uint)Marshal.GetLastWin32Error());
44+
45+
private static unsafe string GetErrorMessage(uint errorCode)
46+
{
47+
IntPtr* messagePtr = stackalloc IntPtr[1];
48+
var messageLength = PInvoke.FormatMessage(
49+
FORMAT_MESSAGE_OPTIONS.FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_OPTIONS.FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_OPTIONS.FORMAT_MESSAGE_IGNORE_INSERTS,
50+
default,
51+
errorCode,
52+
0,
53+
new PWSTR((char*)messagePtr),
54+
0);
55+
var message = *messagePtr;
56+
try
57+
{
58+
return Marshal.PtrToStringUni(message, (int)messageLength);
59+
}
60+
finally
61+
{
62+
PInvoke.LocalFree(new HLOCAL(message.ToPointer()));
63+
}
3564
}
3665
}

src/Uno.UI.Runtime.Skia.Win32.Support/Uno.UI.Runtime.Skia.Win32.Support.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
<Nullable>enable</Nullable>
2121
</PropertyGroup>
2222

23+
<ItemGroup>
24+
<ProjectReference Include="..\Uno.Foundation.Logging\Uno.Foundation.Logging.csproj" />
25+
</ItemGroup>
26+
2327
<ItemGroup>
2428
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106" />
2529
</ItemGroup>

0 commit comments

Comments
 (0)