Compute wxDCImpl::m_mm_to_pix_[xy] on demand

If nothing else, this avoids 2 calls to each of wxGetDisplaySize() and
wxGetDisplaySizeMM() on each and every wxGCDC construction which are
completely unnecessary as wxGCDCImpl uses its own hardcoded resolution
of 72 DPI, as do some other classes deriving from wxDCImpl.

And even for the classes which do compute these fields using the display
resolution, it may still be unnecessary to do it as they can be never
used if neither GetSizeMM() nor SetLogicalScale() are called on the
corresponding wxDC object.

Finally, this is more than an optimization as when using Cairo-based
wxGCDC without display (which is explicitly supported), calling
wxGetDisplaySize() simply doesn't work at all.
This commit is contained in:
Vadim Zeitlin
2018-12-06 03:19:42 +01:00
parent e1a702a205
commit 3dc16a7419
11 changed files with 61 additions and 30 deletions

View File

@@ -390,9 +390,9 @@ void wxGCDCImpl::DoGetSizeMM( int* width, int* height ) const
GetOwner()->GetSize( &w, &h );
if (width)
*width = long( double(w) / (m_scaleX * m_mm_to_pix_x) );
*width = long( double(w) / (m_scaleX * GetMMToPXx()) );
if (height)
*height = long( double(h) / (m_scaleY * m_mm_to_pix_y) );
*height = long( double(h) / (m_scaleY * GetMMToPXy()) );
}
void wxGCDCImpl::SetTextForeground( const wxColour &col )