Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc - High-DPI support is now enabled by default in Chromium #4410

Open
amaitland opened this issue Feb 27, 2023 · 8 comments
Open

Doc - High-DPI support is now enabled by default in Chromium #4410

amaitland opened this issue Feb 27, 2023 · 8 comments

Comments

@amaitland
Copy link
Member

amaitland commented Feb 27, 2023

Starting in M108 High-DPI support is now enabled by default in Chromium.

Additionally, as a refactor to move responsibility out of the embedder
this change moves the existing EnableHighDPISupport calls in
chrome_exe_main_win.cc into the respective GpuMain &
BrowserMainRunnerImpl for the GPU & Browser processes.

chromiumembedded/cef#3452

amaitland added a commit to cefsharp/CefSharp.MinimalExample that referenced this issue Mar 7, 2023
- Remove DPI entries from app.manifest
- Remove Cef.EnableHighDPISupport (Method will be removed in M113 (cefsharp/CefSharp#4417))

Issue cefsharp/CefSharp#4410
amaitland added a commit that referenced this issue Mar 7, 2023
- Chromium now enables DPI awareness programmatically by default
- Remove Cef.EnableHighDPISupport calls and mark as obsolete
- Remove dpiawareness entries from app.manifest

Issues #4417 #4410
@amaitland
Copy link
Member Author

For WPF the default would appear to be still System aware, WPF must be setting that somewhere internally (which makes sense as that's the default that WPF uses). So setting via the app.manifest is still required.

amaitland added a commit that referenced this issue Mar 13, 2023
- NetCore has it's own exe which still had a call to EnableHighDPISupport
- WPF seems to default to System DPI aware, revert to using app.manifest for PerMonitorV2

Follow up to b17cd2a

Issues #4417 #4410
@amaitland amaitland added this to the 111.1.x milestone Mar 13, 2023
amaitland added a commit that referenced this issue Mar 13, 2023
- NetCore has it's own exe which still had a call to EnableHighDPISupport
- WPF seems to default to System DPI aware, revert to using app.manifest for PerMonitorV2

Follow up to b17cd2a

Issues #4417 #4410
@amaitland amaitland changed the title Doc - Chromium DPI Awareness Changes Doc - High-DPI support is now enabled by default in Chromium Mar 15, 2023
@amaitland
Copy link
Member Author

amaitland commented Mar 15, 2023

M111 will be the first version to rely on the Chromium default. The BrowserSubProcess no longer has app.manifest entries for DPI Awareness. Setting the DPI Awareness programmatically looks like it also influences the GPU process. See #2927 (comment)

@UweKeim
Copy link

UweKeim commented May 9, 2023

I want to continue using CefSharp in a WinForms app that is currently not yet capable of running in High-DPI mode.

Is there still a way to fall back to non-High-DPI mode?


Update 1

It seems that disabling High-DPI through the application manifest did not help.

Instead, I removed all High-DPI related stuff from the manifest and instead did call the following right at the beginning of my application:

SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE);

So far, it seems that this works.

(Context: I'm using CefSharp as "self-hosted" in a .NET 7 WinForms application, 64-bit)

@Yokomoko
Copy link

I cannot seem to find this SetProcessDpiAwarenessContext method, do you know where this is? As I also need this.

@UweKeim
Copy link

UweKeim commented May 10, 2023

@Yokomoko Sure, it is P/Invoke:

[DllImport(@"user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetProcessDpiAwarenessContext(IntPtr dpiAWarenessContext);

private const int DPI_AWARENESS_CONTEXT_UNAWARE = -1;
private const int DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED = -5;

My call then looks like:

var r = SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE);
if (!r)
{
    var error = Marshal.GetLastWin32Error();
    Trace.TraceWarning($@"Error settings DPI awareness: {error}.");
}

@amaitland amaitland modified the milestones: 112.2.x, 113.0.x May 12, 2023
@amaitland amaitland modified the milestones: 113.1.x, 114.2.x Jun 8, 2023
@amaitland amaitland modified the milestones: 114.2.x, 115.2.x Jul 26, 2023
@amaitland amaitland modified the milestones: 115.2.x, 116.0.x Aug 19, 2023
@amaitland amaitland modified the milestones: 116.0.x, 117.2.x Oct 8, 2023
@amaitland amaitland modified the milestones: 117.2.x, 118.6.x Oct 27, 2023
@amaitland amaitland removed this from the 118.6.x milestone Nov 10, 2023
@amaitland amaitland added this to the 119.1.x milestone Nov 10, 2023
@amaitland amaitland removed this from the 119.1.x milestone Dec 16, 2023
@jquerijero
Copy link

jquerijero commented May 24, 2024

There is a bitmap scaling that is used by Terminal Server and newer Windows versions for non-DPI aware (manifest not modified) application. Chromium instance is overriding that function by re-rendering the application (including windows that doesn't contain an embedded browser) causing it to resize and remove bitmap scaling.

@amaitland
Copy link
Member Author

Chromium instance is overriding that function by re-rendering the application

Chromium uses Per Monitor V2 by default.

You can override this behaviour as

Setting the DPI Awareness programmatically looks like it also influences the GPU process. See #2927 (comment)

There are some additional examples of setting DPI awareness programmatically.

@amaitland
Copy link
Member Author

In the context of WinForms. Setting DPI Awareness via app.manifest is no longer recommended when using .Net 4.8 or greater (this includes newer versions including .Net 8.0).

See https://learn.microsoft.com/en-us/dotnet/desktop/winforms/wfdev-diagnostics/wfac010?view=netdesktop-8.0 for Microsoft guidance regarding the compiler warning that will be raised.

Starting in .Net Core 3.0 you can use the WinForms specific API. Some examples (refer to the Microsoft documentation for more details)

Application.SetHighDpiMode(HighDpiMode.DpiUnaware);
Application.SetHighDpiMode(HighDpiMode.DpiUnawareGdiScaled);
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.SetHighDpiMode(HighDpiMode.PerMonitor);
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.application.sethighdpimode?view=windowsdesktop-8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants