GAL: Add antialiasing options to Cairo

Cairo supports antialiasing when rendering but can be slow when set to
sub-pixel mode.  This bumps the minimum version of Cairo to 1.12
(available in 14.04 LTS as well as mingw) to support three antialias
settings (fast, good, best) that offer speed/appearance tradeoffs.

This can provide a higher-quality eeschema render as it works on a
per-element basis as opposed to the OpenGL per-screen antialias.
This commit is contained in:
Seth Hillbrand 2018-01-04 05:13:00 -07:00
parent b743c39ed8
commit e8333633fe
15 changed files with 333 additions and 832 deletions

View File

@ -604,7 +604,7 @@ endif()
#
# Find Cairo library, required
#
find_package( Cairo 1.8.8 REQUIRED )
find_package( Cairo 1.12 REQUIRED )
find_package( Pixman 0.30 REQUIRED )
#

View File

@ -60,6 +60,9 @@ bool PANEL_COMMON_SETTINGS::TransferDataToWindow()
commonSettings->Read( GAL_ANTIALIASING_MODE_KEY, &antialiasingMode, 0 );
m_antialiasing->SetSelection( antialiasingMode );
commonSettings->Read( CAIRO_ANTIALIASING_MODE_KEY, &antialiasingMode, 0 );
m_antialiasingFallback->SetSelection( antialiasingMode );
int scale_fourths;
commonSettings->Read( ICON_SCALE_KEY, &scale_fourths );
@ -106,6 +109,8 @@ bool PANEL_COMMON_SETTINGS::TransferDataFromWindow()
commonSettings->Write( GAL_ANTIALIASING_MODE_KEY, m_antialiasing->GetSelection() );
commonSettings->Write( CAIRO_ANTIALIASING_MODE_KEY, m_antialiasingFallback->GetSelection() );
const int scale_fourths = m_scaleAuto->GetValue() ? -1 : m_scaleSlider->GetValue() / 25;
commonSettings->Write( ICON_SCALE_KEY, scale_fourths );

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jul 11 2018)
// C++ code generated with wxFormBuilder (version Nov 23 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -9,7 +9,7 @@
///////////////////////////////////////////////////////////////////////////
PANEL_COMMON_SETTINGS_BASE::PANEL_COMMON_SETTINGS_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style )
PANEL_COMMON_SETTINGS_BASE::PANEL_COMMON_SETTINGS_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name )
{
wxBoxSizer* bPanelSizer;
bPanelSizer = new wxBoxSizer( wxVERTICAL );
@ -51,7 +51,7 @@ PANEL_COMMON_SETTINGS_BASE::PANEL_COMMON_SETTINGS_BASE( wxWindow* parent, wxWind
gbSizer1->Add( m_fileHistorySize, wxGBPosition( 1, 1 ), wxGBSpan( 1, 1 ), wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 );
wxStaticText* antialiasingLabel;
antialiasingLabel = new wxStaticText( this, wxID_ANY, _("Graphics acceleration:"), wxDefaultPosition, wxDefaultSize, 0 );
antialiasingLabel = new wxStaticText( this, wxID_ANY, _("Graphics (Accelerated):"), wxDefaultPosition, wxDefaultSize, 0 );
antialiasingLabel->Wrap( -1 );
gbSizer1->Add( antialiasingLabel, wxGBPosition( 3, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
@ -61,6 +61,17 @@ PANEL_COMMON_SETTINGS_BASE::PANEL_COMMON_SETTINGS_BASE( wxWindow* parent, wxWind
m_antialiasing->SetSelection( 0 );
gbSizer1->Add( m_antialiasing, wxGBPosition( 3, 1 ), wxGBSpan( 1, 2 ), wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
wxStaticText* antialiasingLabel1;
antialiasingLabel1 = new wxStaticText( this, wxID_ANY, _("Graphics (Fallback):"), wxDefaultPosition, wxDefaultSize, 0 );
antialiasingLabel1->Wrap( -1 );
gbSizer1->Add( antialiasingLabel1, wxGBPosition( 4, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
wxString m_antialiasingFallbackChoices[] = { _("No Antialiasing"), _("Fast Antialiasing"), _("Balanced Antialiasing"), _("High Quality Antialiasing") };
int m_antialiasingFallbackNChoices = sizeof( m_antialiasingFallbackChoices ) / sizeof( wxString );
m_antialiasingFallback = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_antialiasingFallbackNChoices, m_antialiasingFallbackChoices, 0 );
m_antialiasingFallback->SetSelection( 0 );
gbSizer1->Add( m_antialiasingFallback, wxGBPosition( 4, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
gbSizer1->AddGrowableCol( 1 );
@ -88,7 +99,7 @@ PANEL_COMMON_SETTINGS_BASE::PANEL_COMMON_SETTINGS_BASE( wxWindow* parent, wxWind
gridHelperApps->Add( m_textEditorPath, wxGBPosition( 0, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
m_textEditorBtn = new wxBitmapButton( sizerHelperApps->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
m_textEditorBtn = new wxBitmapButton( sizerHelperApps->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
m_textEditorBtn->SetMinSize( wxSize( 29,29 ) );
gridHelperApps->Add( m_textEditorBtn, wxGBPosition( 0, 2 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 );
@ -104,7 +115,7 @@ PANEL_COMMON_SETTINGS_BASE::PANEL_COMMON_SETTINGS_BASE( wxWindow* parent, wxWind
gridHelperApps->Add( m_PDFViewerPath, wxGBPosition( 3, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
m_pdfViewerBtn = new wxBitmapButton( sizerHelperApps->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
m_pdfViewerBtn = new wxBitmapButton( sizerHelperApps->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 );
m_pdfViewerBtn->SetMinSize( wxSize( 29,29 ) );
gridHelperApps->Add( m_pdfViewerBtn, wxGBPosition( 3, 2 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 );

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,11 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jul 11 2018)
// C++ code generated with wxFormBuilder (version Nov 23 2018)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __PANEL_COMMON_SETTINGS_BASE_H__
#define __PANEL_COMMON_SETTINGS_BASE_H__
#pragma once
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
@ -54,6 +53,7 @@ class PANEL_COMMON_SETTINGS_BASE : public wxPanel
wxStaticText* m_staticTextFileHistorySize;
wxSpinCtrl* m_fileHistorySize;
wxChoice* m_antialiasing;
wxChoice* m_antialiasingFallback;
wxTextCtrl* m_textEditorPath;
wxBitmapButton* m_textEditorBtn;
wxRadioButton* m_defaultPDFViewer;
@ -79,9 +79,8 @@ class PANEL_COMMON_SETTINGS_BASE : public wxPanel
public:
PANEL_COMMON_SETTINGS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxTAB_TRAVERSAL );
PANEL_COMMON_SETTINGS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
~PANEL_COMMON_SETTINGS_BASE();
};
#endif //__PANEL_COMMON_SETTINGS_BASE_H__

View File

@ -34,7 +34,8 @@
using namespace KIGFX;
CAIRO_COMPOSITOR::CAIRO_COMPOSITOR( cairo_t** aMainContext ) :
m_current( 0 ), m_currentContext( aMainContext ), m_mainContext( *aMainContext )
m_current( 0 ), m_currentContext( aMainContext ), m_mainContext( *aMainContext ),
m_currentAntialiasingMode( CAIRO_ANTIALIAS_NONE )
{
// Do not have uninitialized members:
cairo_matrix_init_identity( &m_matrix );
@ -55,6 +56,28 @@ void CAIRO_COMPOSITOR::Initialize()
}
void CAIRO_COMPOSITOR::SetAntialiasingMode( CAIRO_ANTIALIASING_MODE aMode )
{
switch( aMode )
{
case CAIRO_ANTIALIASING_MODE::FAST:
m_currentAntialiasingMode = CAIRO_ANTIALIAS_FAST;
break;
case CAIRO_ANTIALIASING_MODE::GOOD:
m_currentAntialiasingMode = CAIRO_ANTIALIAS_GOOD;
break;
case CAIRO_ANTIALIASING_MODE::BEST:
m_currentAntialiasingMode = CAIRO_ANTIALIAS_BEST;
break;
default:
m_currentAntialiasingMode = CAIRO_ANTIALIAS_NONE;
}
clean();
}
void CAIRO_COMPOSITOR::Resize( unsigned int aWidth, unsigned int aHeight )
{
clean();
@ -86,7 +109,7 @@ unsigned int CAIRO_COMPOSITOR::CreateBuffer()
#endif /* __WXDEBUG__ */
// Set default settings for the buffer
cairo_set_antialias( context, CAIRO_ANTIALIAS_NONE );
cairo_set_antialias( context, m_currentAntialiasingMode );
cairo_set_line_join( context, CAIRO_LINE_JOIN_ROUND );
cairo_set_line_cap( context, CAIRO_LINE_CAP_ROUND );

View File

@ -739,6 +739,7 @@ void CAIRO_GAL_BASE::EnableDepthTest( bool aEnabled )
void CAIRO_GAL_BASE::resetContext()
{
cairo_set_antialias( context, CAIRO_ANTIALIAS_NONE );
ClearScreen();
@ -1227,6 +1228,7 @@ void CAIRO_GAL::setCompositor()
// Recreate the compositor with the new Cairo context
compositor.reset( new CAIRO_COMPOSITOR( &currentContext ) );
compositor->Resize( screenSize.x, screenSize.y );
compositor->SetAntialiasingMode( options.cairo_antialiasing_mode );
// Prepare buffers
mainBuffer = compositor->CreateBuffer();
@ -1254,6 +1256,16 @@ bool CAIRO_GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions )
{
bool refresh = false;
if( validCompositor && aOptions.cairo_antialiasing_mode != compositor->GetAntialiasingMode() )
{
compositor->SetAntialiasingMode( options.cairo_antialiasing_mode );
validCompositor = false;
deinitSurface();
refresh = true;
}
if( super::updatedGalDisplayOptions( aOptions ) )
{
Refresh();

View File

@ -49,6 +49,7 @@ static const UTIL::CFG_MAP<KIGFX::GRID_STYLE> gridStyleConfigVals =
GAL_DISPLAY_OPTIONS::GAL_DISPLAY_OPTIONS()
: gl_antialiasing_mode( OPENGL_ANTIALIASING_MODE::NONE ),
cairo_antialiasing_mode( CAIRO_ANTIALIASING_MODE::NONE ),
m_gridStyle( GRID_STYLE::DOTS ),
m_gridLineWidth( 0.5 ),
m_gridMinSpacing( 10.0 ),

View File

@ -302,6 +302,10 @@ void EDA_DRAW_FRAME::CommonSettingsChanged()
int tmp;
settings->Read( GAL_ANTIALIASING_MODE_KEY, &tmp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) tmp;
settings->Read( CAIRO_ANTIALIASING_MODE_KEY, &tmp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) tmp;
m_galDisplayOptions.NotifyChanged();
}
@ -849,6 +853,10 @@ void EDA_DRAW_FRAME::LoadSettings( wxConfigBase* aCfg )
int temp;
cmnCfg->Read( GAL_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) temp;
cmnCfg->Read( CAIRO_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) temp;
m_galDisplayOptions.NotifyChanged();
}

View File

@ -304,6 +304,10 @@ void EDA_DRAW_FRAME::CommonSettingsChanged()
int tmp;
settings->Read( GAL_ANTIALIASING_MODE_KEY, &tmp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) tmp;
settings->Read( CAIRO_ANTIALIASING_MODE_KEY, &tmp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) tmp;
m_galDisplayOptions.NotifyChanged();
}
@ -868,6 +872,10 @@ void EDA_DRAW_FRAME::LoadSettings( wxConfigBase* aCfg )
int temp;
cmnCfg->Read( GAL_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) temp;
cmnCfg->Read( CAIRO_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) temp;
m_galDisplayOptions.NotifyChanged();
}

View File

@ -553,7 +553,8 @@ void PGM_BASE::loadCommonSettings()
m_common_settings->Write( USE_ICONS_IN_MENUS_KEY, defaultUseIconsInMenus );
if( !m_common_settings->HasEntry( ICON_SCALE_KEY )
|| !m_common_settings->HasEntry( GAL_ANTIALIASING_MODE_KEY ) )
|| !m_common_settings->HasEntry( GAL_ANTIALIASING_MODE_KEY )
|| !m_common_settings->HasEntry( CAIRO_ANTIALIASING_MODE_KEY ) )
{
// 5.0 and earlier saved common settings in each app, and saved hardware antialiasing
// options only in pcbnew (which was the only canvas to support them). Since there's
@ -588,6 +589,14 @@ void PGM_BASE::loadCommonSettings()
&temp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE );
m_common_settings->Write( GAL_ANTIALIASING_MODE_KEY, temp );
}
if( !m_common_settings->HasEntry( CAIRO_ANTIALIASING_MODE_KEY ) )
{
int temp;
pcbnewConfig->Read( pcbFrameKey + GAL_DISPLAY_OPTIONS_KEY + CAIRO_ANTIALIASING_MODE_KEY,
&temp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE );
m_common_settings->Write( CAIRO_ANTIALIASING_MODE_KEY, temp );
}
}
m_editor_name = m_common_settings->Read( "Editor" );

View File

@ -32,6 +32,7 @@
#define CAIRO_COMPOSITOR_H_
#include <gal/compositor.h>
#include <gal/gal_display_options.h>
#include <cairo.h>
#include <boost/smart_ptr/shared_array.hpp>
#include <deque>
@ -74,6 +75,22 @@ public:
/// @copydoc COMPOSITOR::Present()
virtual void Present() override;
void SetAntialiasingMode( CAIRO_ANTIALIASING_MODE aMode ); // clears all buffers
CAIRO_ANTIALIASING_MODE GetAntialiasingMode() const
{
switch( m_currentAntialiasingMode )
{
case CAIRO_ANTIALIAS_FAST:
return CAIRO_ANTIALIASING_MODE::FAST;
case CAIRO_ANTIALIAS_GOOD:
return CAIRO_ANTIALIASING_MODE::GOOD;
case CAIRO_ANTIALIAS_BEST:
return CAIRO_ANTIALIASING_MODE::BEST;
default:
return CAIRO_ANTIALIASING_MODE::NONE;
}
}
/**
* Function SetMainContext()
* Sets a context to be treated as the main context (ie. as a target of buffers rendering and
@ -116,6 +133,8 @@ protected:
unsigned int m_stride; ///< Stride to use given the desired format and width
unsigned int m_bufferSize; ///< Amount of memory needed to store a buffer
cairo_antialias_t m_currentAntialiasingMode;
/**
* Function clean()
* performs freeing of resources.

View File

@ -50,6 +50,14 @@ namespace KIGFX
SUPERSAMPLING_X4,
};
enum class CAIRO_ANTIALIASING_MODE
{
NONE,
FAST,
GOOD,
BEST,
};
class GAL_DISPLAY_OPTIONS;
class GAL_DISPLAY_OPTIONS_OBSERVER
@ -73,6 +81,8 @@ namespace KIGFX
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode;
CAIRO_ANTIALIASING_MODE cairo_antialiasing_mode;
///> The grid style to draw the grid in
KIGFX::GRID_STYLE m_gridStyle;

View File

@ -52,6 +52,7 @@
#define FILE_HISTORY_SIZE_KEY wxT( "FileHistorySize" )
#define GAL_DISPLAY_OPTIONS_KEY wxT( "GalDisplayOptions" )
#define GAL_ANTIALIASING_MODE_KEY wxT( "OpenGLAntialiasingMode" )
#define CAIRO_ANTIALIASING_MODE_KEY wxT( "CairoAntialiasingMode" )
///@}

View File

@ -390,6 +390,9 @@ FOOTPRINT_PREVIEW_PANEL* FOOTPRINT_PREVIEW_PANEL::New( KIWAY* aKiway, wxWindow*
commonCfg->Read( GAL_ANTIALIASING_MODE_KEY, &itemp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE );
gal_opts.gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) itemp;
commonCfg->Read( CAIRO_ANTIALIASING_MODE_KEY, &itemp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE );
gal_opts.cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) itemp;
}
#ifdef __WXMAC__