Remove the platform-specific GetBackendScalingFactor from HIDPI_GL_CANVAS

The scaling factor stored inside the canvas is created by a DPI_SCALING
helper, which will call the platform-specific functions if no user scaling
is specified. This change only affects OSX and Retina displays, so this
now also allows custom scaling to be used on OSX if desired (although it
shouldn't be needed, since wx has detection for it in 3.0.4).
This commit is contained in:
Ian McInerney 2020-06-03 23:22:37 +01:00 committed by Ian McInerney
parent 916d06c1e6
commit ab83c86210
4 changed files with 11 additions and 24 deletions

View File

@ -174,7 +174,9 @@ Most of these will not be available in general distributions until v3.2.
C.f. [this commit](https://github.com/wxWidgets/wxWidgets/commit/f95fd11e08482697c3b0c0a9d2ccd661134480ee)
`dpi_scaling.cpp` should continue to work normally, but the config should
no longer be required and the scaling should auto-detect.
* Once the minimum version is greater than 3.1.3, the code inside the constructor of the `HIDPI_GL_CANVAS`
should be removed, since the default behavior of a `wxGLCanvas` was changed in 3.1.3 to always want the
best resolution.
[Boost test]: https://github.com/boostorg/test
[GCC 7]: https://gcc.gnu.org/gcc-7/changes.html

View File

@ -35,6 +35,8 @@ HIDPI_GL_CANVAS::HIDPI_GL_CANVAS( wxWindow* parent, wxWindowID id, const int* at
: wxGLCanvas( parent, id, attribList, pos, size, style, name, palette ),
m_scale_factor( DPI_SCALING::GetDefaultScaleFactor() )
{
// As of wxWidgets version 3.1.3, this is the default behavior of the wxGLCanvas on OSX
// so this piece of code can be removed once our minimum version is >3.1.3 for OSX.
#ifdef RETINA_OPENGL_PATCH
SetViewWantsBestResolution( true );
#endif
@ -45,7 +47,7 @@ wxSize HIDPI_GL_CANVAS::GetNativePixelSize() const
{
wxSize size = wxGLCanvas::GetClientSize();
const float scaleFactor = GetBackingScaleFactor();
const double scaleFactor = GetScaleFactor();
size.x *= scaleFactor;
size.y *= scaleFactor;
@ -53,20 +55,6 @@ wxSize HIDPI_GL_CANVAS::GetNativePixelSize() const
}
float HIDPI_GL_CANVAS::GetBackingScaleFactor() const
{
#ifdef RETINA_OPENGL_PATCH
// this is ugly, but original method isn't marked const although it doesn't modify anything
// => clean up when it officially has arrived in wxWidgets
return static_cast< wxGLCanvas* >( const_cast< HIDPI_GL_CANVAS* >( this ))->GetBackingScaleFactor();
#else
// Return the cached value (which originally was set from config or automatically)
return m_scale_factor;
#endif
}
void HIDPI_GL_CANVAS::SetScaleFactor( double aNewScaleFactor )
{
m_scale_factor = aNewScaleFactor;
@ -76,4 +64,4 @@ void HIDPI_GL_CANVAS::SetScaleFactor( double aNewScaleFactor )
double HIDPI_GL_CANVAS::GetScaleFactor() const
{
return m_scale_factor;
}
}

View File

@ -374,7 +374,7 @@ double OPENGL_GAL::getWorldPixelSize() const
VECTOR2D OPENGL_GAL::getScreenPixelSize() const
{
auto sf = GetBackingScaleFactor();
auto sf = GetScaleFactor();
return VECTOR2D( 2.0 / (double) ( screenSize.x * sf ), 2.0 / (double) ( screenSize.y * sf ) );
}
@ -500,7 +500,7 @@ void OPENGL_GAL::beginDrawing()
}
shader->Use();
shader->SetParameter( ufm_worldPixelSize, (float) getWorldPixelSize() / GetBackingScaleFactor() );
shader->SetParameter( ufm_worldPixelSize, (float) ( getWorldPixelSize() / GetScaleFactor() ) );
shader->SetParameter( ufm_screenPixelSize, getScreenPixelSize() );
double pixelSizeMultiplier = compositor->GetAntialiasSupersamplingFactor();
shader->SetParameter( ufm_pixelSizeMultiplier, (float) pixelSizeMultiplier );
@ -1245,7 +1245,7 @@ void OPENGL_GAL::DrawGrid()
// sub-pixel lines all render the same
float minorLineWidth =
std::fmax( 1.0f, gridLineWidth ) * getWorldPixelSize() / GetBackingScaleFactor();
std::fmax( 1.0f, gridLineWidth ) * getWorldPixelSize() / GetScaleFactor();
float majorLineWidth = minorLineWidth * 2.0f;
// Draw the axis and grid
@ -1399,7 +1399,7 @@ void OPENGL_GAL::ResizeScreen( int aWidth, int aHeight )
screenSize = VECTOR2I( aWidth, aHeight );
// Resize framebuffers
const float scaleFactor = GetBackingScaleFactor();
const float scaleFactor = GetScaleFactor();
compositor->Resize( aWidth * scaleFactor, aHeight * scaleFactor );
isFramebufferInitialized = false;

View File

@ -34,8 +34,6 @@
* @brief wxGLCanvas wrapper for HiDPI/Retina support.
*
* This is a small wrapper class to enable HiDPI/Retina support for wxGLCanvas.
* HiDPI currently only works with a patched wxWidgets version, see:
* http://trac.wxwidgets.org/ticket/15700
*/
class HIDPI_GL_CANVAS : public wxGLCanvas
{
@ -52,7 +50,6 @@ public:
virtual wxSize GetNativePixelSize() const;
virtual float GetBackingScaleFactor() const;
/**
* Set the canvas scale factor, probably for a hi-DPI display.