From 371ee79f88093b9fe7b05f44e6dfe77ac2a9708a Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Mon, 22 Feb 2016 10:25:16 -0800 Subject: [PATCH] Avoid wxGraphicsContext offsetting on HiDPI displays For a typical scale factor of 2, there won't be any odd-width lines, and for any factor greater than 1.0, it won't be doing what was intended, so just don't do it. See #17375 --- src/generic/graphicc.cpp | 6 +++--- src/gtk/dc.cpp | 12 ++++++------ src/osx/carbon/dcclient.cpp | 2 +- src/osx/carbon/graphics.cpp | 6 +++--- src/osx/core/dcmemory.cpp | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 4570603ec9..891d734887 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -1724,7 +1724,7 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC& m_width = width; m_height = height; - m_enableOffset = true; + m_enableOffset = dc.GetContentScaleFactor() <= 1; #ifdef __WXMSW__ m_mswSurface = cairo_win32_surface_create((HDC)dc.GetHDC()); @@ -1789,7 +1789,7 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC& m_width = width; m_height = height; - m_enableOffset = true; + m_enableOffset = dc.GetContentScaleFactor() <= 1; #ifdef __WXMSW__ @@ -1919,7 +1919,7 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, wxWindow *window) , m_mswWindowHDC(GetHwndOf(window)) #endif { - m_enableOffset = true; + m_enableOffset = window->GetContentScaleFactor() <= 1; #ifdef __WXGTK__ // something along these lines (copied from dcclient) diff --git a/src/gtk/dc.cpp b/src/gtk/dc.cpp index 16217e67ca..e87585b6d5 100644 --- a/src/gtk/dc.cpp +++ b/src/gtk/dc.cpp @@ -210,7 +210,7 @@ wxWindowDCImpl::wxWindowDCImpl(wxWindowDC* owner, wxWindow* window) { cairo_t* cr = gdk_cairo_create(gdkWindow); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); - gc->EnableOffset(true); + gc->EnableOffset(m_contentScaleFactor <= 1); SetGraphicsContext(gc); GtkAllocation a; gtk_widget_get_allocation(widget, &a); @@ -255,7 +255,7 @@ wxClientDCImpl::wxClientDCImpl(wxClientDC* owner, wxWindow* window) { cairo_t* cr = gdk_cairo_create(gdkWindow); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); - gc->EnableOffset(true); + gc->EnableOffset(m_contentScaleFactor <= 1); SetGraphicsContext(gc); if (gtk_widget_get_has_window(widget)) { @@ -288,7 +288,7 @@ wxPaintDCImpl::wxPaintDCImpl(wxPaintDC* owner, wxWindow* window) m_height = gdk_window_get_height(gdkWindow); cairo_reference(cr); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); - gc->EnableOffset(true); + gc->EnableOffset(m_contentScaleFactor <= 1); SetGraphicsContext(gc); } //----------------------------------------------------------------------------- @@ -301,7 +301,7 @@ wxScreenDCImpl::wxScreenDCImpl(wxScreenDC* owner) m_height = gdk_window_get_height(window); cairo_t* cr = gdk_cairo_create(window); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); - gc->EnableOffset(true); + gc->EnableOffset(m_contentScaleFactor <= 1); SetGraphicsContext(gc); } //----------------------------------------------------------------------------- @@ -357,7 +357,7 @@ void wxMemoryDCImpl::Setup() m_contentScaleFactor = m_bitmap.GetScaleFactor(); cairo_t* cr = m_bitmap.CairoCreate(); gc = wxGraphicsContext::CreateFromNative(cr); - gc->EnableOffset(true); + gc->EnableOffset(m_contentScaleFactor <= 1); } SetGraphicsContext(gc); } @@ -368,7 +368,7 @@ wxGTKCairoDC::wxGTKCairoDC(cairo_t* cr, wxWindow* window) { cairo_reference(cr); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); - gc->EnableOffset(true); + gc->EnableOffset(window->GetContentScaleFactor() <= 1); SetGraphicsContext(gc); } diff --git a/src/osx/carbon/dcclient.cpp b/src/osx/carbon/dcclient.cpp index 1ef4792d12..9798ab24aa 100644 --- a/src/osx/carbon/dcclient.cpp +++ b/src/osx/carbon/dcclient.cpp @@ -76,7 +76,7 @@ wxWindowDCImpl::wxWindowDCImpl( wxDC *owner, wxWindow *window ) CGContextTranslateCTM( cg , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ); wxGraphicsContext* context = wxGraphicsContext::CreateFromNative( cg ); - context->EnableOffset(true); + context->EnableOffset(m_contentScaleFactor <= 1); SetGraphicsContext( context ); } DoSetClippingRegion( 0 , 0 , m_width , m_height ) ; diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index ee53b906a9..92b3400784 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -1532,7 +1532,7 @@ wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer* renderer { Init(); - m_enableOffset = true; + m_enableOffset = window->GetContentScaleFactor() <= 1; wxSize sz = window->GetSize(); m_width = sz.x; m_height = sz.y; @@ -2622,7 +2622,7 @@ wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContext( const wxWindowDC& // this is the case for all wxWindowDCs except wxPaintDC wxMacCoreGraphicsContext *context = new wxMacCoreGraphicsContext( this, cgctx, (wxDouble) w, (wxDouble) h ); - context->EnableOffset(true); + context->EnableOffset(dc.GetContentScaleFactor() < 2); return context; } return NULL; @@ -2639,7 +2639,7 @@ wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContext( const wxMemoryDC& mem_impl->GetSize( &w, &h ); wxMacCoreGraphicsContext* context = new wxMacCoreGraphicsContext( this, (CGContextRef)(mem_impl->GetGraphicsContext()->GetNativeContext()), (wxDouble) w, (wxDouble) h ); - context->EnableOffset(true); + context->EnableOffset(dc.GetContentScaleFactor() < 2); return context; } #endif diff --git a/src/osx/core/dcmemory.cpp b/src/osx/core/dcmemory.cpp index 1adf3789cc..aeb700ddff 100644 --- a/src/osx/core/dcmemory.cpp +++ b/src/osx/core/dcmemory.cpp @@ -87,7 +87,7 @@ void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap ) CGContextSetStrokeColorSpace( bmCtx, genericColorSpace ); SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) ); if (m_graphicContext) - m_graphicContext->EnableOffset(true); + m_graphicContext->EnableOffset(m_contentScaleFactor <= 1); } m_ok = (m_graphicContext != NULL) ; }