From f572797965158a7df0f302758f9f61295e058814 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 7 Aug 2020 00:15:26 +0200 Subject: [PATCH] Use wxDisplay::GetScaleFactor() in wxWindow::GetDPIScaleFactor() This can be more direct and efficient than computing the ratio of DPIs in wxWindow. --- src/common/wincmn.cpp | 45 +++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 563406a801..2919c60416 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -786,25 +786,6 @@ wxSize wxWindowBase::DoGetBestSize() const return best; } -namespace -{ - -static wxSize GetDPIHelper(const wxWindowBase* w) -{ - wxSize dpi; - - if ( w ) - dpi = w->GetDPI(); - if ( !dpi.x || !dpi.y ) - dpi = wxScreenDC().GetPPI(); - if ( !dpi.x || !dpi.y ) - dpi = wxDisplay::GetStdPPI(); - - return dpi; -} - -} - double wxWindowBase::GetContentScaleFactor() const { // By default, we assume that there is no mapping between logical and @@ -817,12 +798,7 @@ double wxWindowBase::GetContentScaleFactor() const double wxWindowBase::GetDPIScaleFactor() const { - const wxSize dpi = GetDPIHelper(this); - - // We use just the vertical component of the DPI because it's the one - // that counts most and, in practice, it's equal to the horizontal one - // anyhow. - return dpi.y / (double)wxDisplay::GetStdPPIValue(); + return wxDisplay(static_cast(this)).GetScaleFactor(); } // helper of GetWindowBorderSize(): as many ports don't implement support for @@ -2887,6 +2863,25 @@ wxSize wxWindowBase::GetDPI() const #ifndef wxHAVE_DPI_INDEPENDENT_PIXELS +namespace +{ + +static wxSize GetDPIHelper(const wxWindowBase* w) +{ + wxSize dpi; + + if ( w ) + dpi = w->GetDPI(); + if ( !dpi.x || !dpi.y ) + dpi = wxScreenDC().GetPPI(); + if ( !dpi.x || !dpi.y ) + dpi = wxDisplay::GetStdPPI(); + + return dpi; +} + +} + /* static */ wxSize wxWindowBase::FromDIP(const wxSize& sz, const wxWindowBase* w)