From ab83c86210c0df9b55facb3e8ef3444590ac2692 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Wed, 3 Jun 2020 23:22:37 +0100 Subject: [PATCH] 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). --- Documentation/development/technical_todo.md | 4 +++- common/gal/hidpi_gl_canvas.cpp | 20 ++++---------------- common/gal/opengl/opengl_gal.cpp | 8 ++++---- include/gal/hidpi_gl_canvas.h | 3 --- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/Documentation/development/technical_todo.md b/Documentation/development/technical_todo.md index 20b92c287a..d94a08a99e 100644 --- a/Documentation/development/technical_todo.md +++ b/Documentation/development/technical_todo.md @@ -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 diff --git a/common/gal/hidpi_gl_canvas.cpp b/common/gal/hidpi_gl_canvas.cpp index fcc0807bf4..b8dfc9a3fc 100644 --- a/common/gal/hidpi_gl_canvas.cpp +++ b/common/gal/hidpi_gl_canvas.cpp @@ -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; -} \ No newline at end of file +} diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 1450add12a..ef6944a790 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -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; diff --git a/include/gal/hidpi_gl_canvas.h b/include/gal/hidpi_gl_canvas.h index ebe3a789a9..58f69a2cb9 100644 --- a/include/gal/hidpi_gl_canvas.h +++ b/include/gal/hidpi_gl_canvas.h @@ -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.