diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index 5b121bf74c..b4282bed8d 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -140,13 +140,25 @@ PCB_DRAW_PANEL_GAL::~PCB_DRAW_PANEL_GAL() void PCB_DRAW_PANEL_GAL::DisplayBoard( BOARD* aBoard ) { + m_view->Clear(); - // Load zones - for( auto zone : aBoard->Zones() ) + auto zones = aBoard->Zones(); + std::atomic next( 0 ); + std::atomic count_done( 0 ); + size_t parallelThreadCount = std::max( std::thread::hardware_concurrency(), 2 ); + + for( size_t ii = 0; ii < parallelThreadCount; ++ii ) { - zone->CacheTriangulation(); - m_view->Add( zone ); + std::thread t = std::thread( [ &count_done, &next, &zones ]( ) + { + for( size_t i = next.fetch_add( 1 ); i < zones.size(); i = next.fetch_add( 1 ) ) + zones[i]->CacheTriangulation(); + + count_done++; + } ); + + t.detach(); } // Load drawings @@ -171,6 +183,14 @@ void PCB_DRAW_PANEL_GAL::DisplayBoard( BOARD* aBoard ) m_view->Add( aBoard->GetMARKER( marker_idx ) ); } + // Finalize the triangulation threads + while( count_done < parallelThreadCount ) + std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); + + // Load zones + for( auto zone : aBoard->Zones() ) + m_view->Add( zone ); + // Ratsnest m_ratsnest.reset( new KIGFX::RATSNEST_VIEWITEM( aBoard->GetConnectivity() ) ); m_view->Add( m_ratsnest.get() );