Simplify PPI and scale factor handling in wxDisplay

Don't try computing the PPI ourselves from the physical size and the
number of pixels, this doesn't work and nobody else does it like this.

Just assume that we're using standard PPI by default and use
toolkit-specific functions for the platforms with support for high DPI.
This commit is contained in:
Vadim Zeitlin
2020-08-14 15:17:59 +02:00
parent 4e6df3f7b2
commit bcb101b9e9
4 changed files with 13 additions and 85 deletions

View File

@@ -153,19 +153,7 @@ double wxDisplay::GetScaleFactor() const
{
wxCHECK_MSG( IsOk(), 0, wxT("invalid wxDisplay object") );
#ifdef wxHAVE_DPI_INDEPENDENT_PIXELS
// Use wxDisplayImpl::GetScaleFactor() directly, it should be implemented
// correctly for the platforms doing pixel scaling and using it simpler and
// more efficient than using GetPPI().
return m_impl->GetScaleFactor();
#else
// Under the other platforms, we just compute the DPI ratio ourselves.
//
// 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 m_impl->GetPPI().y / (double)GetStdPPIValue();
#endif
}
int wxDisplay::GetDepth() const
@@ -226,35 +214,6 @@ bool wxDisplay::ChangeMode(const wxVideoMode& mode)
return *gs_factory;
}
// ============================================================================
// wxDisplayImpl implementation
// ============================================================================
/* static */
wxSize wxDisplayImpl::ComputePPI(int pxX, int pxY, int mmX, int mmY)
{
if ( !mmX || !mmY )
{
// Physical size is unknown, return a special value indicating that we
// can't compute the resolution -- what else can we do?
return wxSize(0, 0);
}
return wxSize(wxRound((pxX * inches2mm) / mmX),
wxRound((pxY * inches2mm) / mmY));
}
wxSize wxDisplayImpl::GetPPI() const
{
const wxSize mm = GetSizeMM();
// We need physical pixels here, not logical ones returned by
// GetGeometry(), to compute the real DPI.
const wxSize pixels = GetGeometry().GetSize()*GetScaleFactor();
return ComputePPI(pixels.x, pixels.y, mm.x, mm.y);
}
// ============================================================================
// wxDisplayFactory implementation
// ============================================================================