Skip to content

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

Open

Description

@amaitland

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

Activity

  1. amaitland commented on Mar 13, 2023

    @amaitland
    MemberAuthor

    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.

  2. added this to the 111.1.x milestone on Mar 13, 2023
  3. changed the title [-]Doc - Chromium DPI Awareness Changes[/-] [+]Doc - High-DPI support is now enabled by default in Chromium[/+] on Mar 15, 2023
  4. amaitland commented on Mar 15, 2023

    @amaitland
    MemberAuthor

    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)

  5. modified the milestones: 111.2.x, 112.2.x on Apr 10, 2023
  6. UweKeim commented on May 9, 2023

    @UweKeim

    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)

  7. Yokomoko commented on May 10, 2023

    @Yokomoko

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

  8. UweKeim commented on May 10, 2023

    @UweKeim

    @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}.");
    }
  9. 4 remaining items

  10. modified the milestones: 114.2.x, 115.2.x on Jul 26, 2023
  11. modified the milestones: 115.2.x, 116.0.x on Aug 19, 2023
  12. modified the milestones: 116.0.x, 117.2.x on Oct 8, 2023
  13. modified the milestones: 117.2.x, 118.6.x on Oct 27, 2023
  14. modified the milestones: 118.6.x, 119.1.x on Nov 10, 2023
  15. removed this from the 119.1.x milestone on Dec 16, 2023
  16. jquerijero commented on May 24, 2024

    @jquerijero

    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.

  17. amaitland commented on May 29, 2024

    @amaitland
    MemberAuthor

    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.

  18. amaitland commented on Jun 25, 2024

    @amaitland
    MemberAuthor

    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

  19. lixiao23 commented on Mar 24, 2025

    @lixiao23

    @UweKeim

    Hello UweKeim,
    Thank you for your assistance and support. By calling the API function, I have successfully resolved the High-DPI issue.
    After setting the value of DPI_AWARENESS_CONTEXT_UNAWARE to "-1", the WinForms application using CefSharp no longer experiences High-DPI problems.

    I believe this is only a temporary solution.
    Could you please confirm whether the latest version of CefSharp still does not provide an option to manually set whether to allow High-DPI?

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions