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
This commit is contained in:
Paul Cornett
2016-02-22 10:25:16 -08:00
parent 6674ca57da
commit 371ee79f88
5 changed files with 14 additions and 14 deletions

View File

@@ -1724,7 +1724,7 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC&
m_width = width; m_width = width;
m_height = height; m_height = height;
m_enableOffset = true; m_enableOffset = dc.GetContentScaleFactor() <= 1;
#ifdef __WXMSW__ #ifdef __WXMSW__
m_mswSurface = cairo_win32_surface_create((HDC)dc.GetHDC()); m_mswSurface = cairo_win32_surface_create((HDC)dc.GetHDC());
@@ -1789,7 +1789,7 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC&
m_width = width; m_width = width;
m_height = height; m_height = height;
m_enableOffset = true; m_enableOffset = dc.GetContentScaleFactor() <= 1;
#ifdef __WXMSW__ #ifdef __WXMSW__
@@ -1919,7 +1919,7 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, wxWindow *window)
, m_mswWindowHDC(GetHwndOf(window)) , m_mswWindowHDC(GetHwndOf(window))
#endif #endif
{ {
m_enableOffset = true; m_enableOffset = window->GetContentScaleFactor() <= 1;
#ifdef __WXGTK__ #ifdef __WXGTK__
// something along these lines (copied from dcclient) // something along these lines (copied from dcclient)

View File

@@ -210,7 +210,7 @@ wxWindowDCImpl::wxWindowDCImpl(wxWindowDC* owner, wxWindow* window)
{ {
cairo_t* cr = gdk_cairo_create(gdkWindow); cairo_t* cr = gdk_cairo_create(gdkWindow);
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
gc->EnableOffset(true); gc->EnableOffset(m_contentScaleFactor <= 1);
SetGraphicsContext(gc); SetGraphicsContext(gc);
GtkAllocation a; GtkAllocation a;
gtk_widget_get_allocation(widget, &a); gtk_widget_get_allocation(widget, &a);
@@ -255,7 +255,7 @@ wxClientDCImpl::wxClientDCImpl(wxClientDC* owner, wxWindow* window)
{ {
cairo_t* cr = gdk_cairo_create(gdkWindow); cairo_t* cr = gdk_cairo_create(gdkWindow);
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
gc->EnableOffset(true); gc->EnableOffset(m_contentScaleFactor <= 1);
SetGraphicsContext(gc); SetGraphicsContext(gc);
if (gtk_widget_get_has_window(widget)) if (gtk_widget_get_has_window(widget))
{ {
@@ -288,7 +288,7 @@ wxPaintDCImpl::wxPaintDCImpl(wxPaintDC* owner, wxWindow* window)
m_height = gdk_window_get_height(gdkWindow); m_height = gdk_window_get_height(gdkWindow);
cairo_reference(cr); cairo_reference(cr);
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
gc->EnableOffset(true); gc->EnableOffset(m_contentScaleFactor <= 1);
SetGraphicsContext(gc); SetGraphicsContext(gc);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -301,7 +301,7 @@ wxScreenDCImpl::wxScreenDCImpl(wxScreenDC* owner)
m_height = gdk_window_get_height(window); m_height = gdk_window_get_height(window);
cairo_t* cr = gdk_cairo_create(window); cairo_t* cr = gdk_cairo_create(window);
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
gc->EnableOffset(true); gc->EnableOffset(m_contentScaleFactor <= 1);
SetGraphicsContext(gc); SetGraphicsContext(gc);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -357,7 +357,7 @@ void wxMemoryDCImpl::Setup()
m_contentScaleFactor = m_bitmap.GetScaleFactor(); m_contentScaleFactor = m_bitmap.GetScaleFactor();
cairo_t* cr = m_bitmap.CairoCreate(); cairo_t* cr = m_bitmap.CairoCreate();
gc = wxGraphicsContext::CreateFromNative(cr); gc = wxGraphicsContext::CreateFromNative(cr);
gc->EnableOffset(true); gc->EnableOffset(m_contentScaleFactor <= 1);
} }
SetGraphicsContext(gc); SetGraphicsContext(gc);
} }
@@ -368,7 +368,7 @@ wxGTKCairoDC::wxGTKCairoDC(cairo_t* cr, wxWindow* window)
{ {
cairo_reference(cr); cairo_reference(cr);
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
gc->EnableOffset(true); gc->EnableOffset(window->GetContentScaleFactor() <= 1);
SetGraphicsContext(gc); SetGraphicsContext(gc);
} }

View File

@@ -76,7 +76,7 @@ wxWindowDCImpl::wxWindowDCImpl( wxDC *owner, wxWindow *window )
CGContextTranslateCTM( cg , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ); CGContextTranslateCTM( cg , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() );
wxGraphicsContext* context = wxGraphicsContext::CreateFromNative( cg ); wxGraphicsContext* context = wxGraphicsContext::CreateFromNative( cg );
context->EnableOffset(true); context->EnableOffset(m_contentScaleFactor <= 1);
SetGraphicsContext( context ); SetGraphicsContext( context );
} }
DoSetClippingRegion( 0 , 0 , m_width , m_height ) ; DoSetClippingRegion( 0 , 0 , m_width , m_height ) ;

View File

@@ -1532,7 +1532,7 @@ wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer* renderer
{ {
Init(); Init();
m_enableOffset = true; m_enableOffset = window->GetContentScaleFactor() <= 1;
wxSize sz = window->GetSize(); wxSize sz = window->GetSize();
m_width = sz.x; m_width = sz.x;
m_height = sz.y; m_height = sz.y;
@@ -2622,7 +2622,7 @@ wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContext( const wxWindowDC&
// this is the case for all wxWindowDCs except wxPaintDC // this is the case for all wxWindowDCs except wxPaintDC
wxMacCoreGraphicsContext *context = wxMacCoreGraphicsContext *context =
new wxMacCoreGraphicsContext( this, cgctx, (wxDouble) w, (wxDouble) h ); new wxMacCoreGraphicsContext( this, cgctx, (wxDouble) w, (wxDouble) h );
context->EnableOffset(true); context->EnableOffset(dc.GetContentScaleFactor() < 2);
return context; return context;
} }
return NULL; return NULL;
@@ -2639,7 +2639,7 @@ wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContext( const wxMemoryDC&
mem_impl->GetSize( &w, &h ); mem_impl->GetSize( &w, &h );
wxMacCoreGraphicsContext* context = new wxMacCoreGraphicsContext( this, wxMacCoreGraphicsContext* context = new wxMacCoreGraphicsContext( this,
(CGContextRef)(mem_impl->GetGraphicsContext()->GetNativeContext()), (wxDouble) w, (wxDouble) h ); (CGContextRef)(mem_impl->GetGraphicsContext()->GetNativeContext()), (wxDouble) w, (wxDouble) h );
context->EnableOffset(true); context->EnableOffset(dc.GetContentScaleFactor() < 2);
return context; return context;
} }
#endif #endif

View File

@@ -87,7 +87,7 @@ void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap )
CGContextSetStrokeColorSpace( bmCtx, genericColorSpace ); CGContextSetStrokeColorSpace( bmCtx, genericColorSpace );
SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) ); SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) );
if (m_graphicContext) if (m_graphicContext)
m_graphicContext->EnableOffset(true); m_graphicContext->EnableOffset(m_contentScaleFactor <= 1);
} }
m_ok = (m_graphicContext != NULL) ; m_ok = (m_graphicContext != NULL) ;
} }