23#include <wx/dcclient.h>
72#include <wx/display.h>
84[[maybe_unused]]
static const wxChar
traceDrawPanel[] = wxT(
"KICAD_DRAW_PANEL" );
172 float dpiScale =
static_cast<float>( GetContentScaleFactor() );
181 wxLogTrace(
traceRhi, wxS(
"DrawPanel: deferred PrepareForExternalRendering "
190 static_cast<uint32_t
>(
cs.x ),
191 static_cast<uint32_t
>(
cs.y ),
204 wxScrolledCanvas( aParentWindow, aWindowId, aPosition, aSize ),
230 SetDoubleBuffered(
false );
234 if(
Pgm().GetCommonSettings()->m_Appearance.show_scrollbars )
235 ShowScrollbars( wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS );
237 ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
239 SetLayoutDirection( wxLayout_LeftToRight );
246 wxWindow* ancestor = aParentWindow->GetParent();
249 ancestor = ancestor->GetParent();
268 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
270 EnableScrolling(
false,
false );
278 const wxEventType events[] = {
306 for( wxEventType eventType : events )
322 wxLogTrace(
traceRhi, wxS(
"DrawPanel: destructor windowId=%u backend=%d" ),
348 wxScrolledCanvas::SetFocus();
376 std::optional<wxPaintDC>
dc;
401 showMessageLater(
_(
"Could not use Metal, switching to OpenGL" ), aDetail,
false );
403 showMessageLater(
_(
"Could not use Vulkan, falling back to software rendering" ), aDetail,
false );
407 wxLogTrace(
traceRhi, wxS(
"DrawPanel: leaving the RHI canvas for backend %d" ),
static_cast<int>(
GAL_FALLBACK ) );
422 galModern->DestroyBuffers();
497 showMessageLater(
_(
"The graphics driver was reset and OpenGL could not be restored" ),
498 _(
"Restart KiCad to use accelerated graphics again." ),
false );
502 showMessageLater(
_(
"Could not use OpenGL, falling back to software rendering" ),
503 wxString( aError.what() ),
false );
512 catch( std::exception& recoveryErr )
514 showMessageLater(
_(
"Graphics error during recovery" ), wxString( recoveryErr.what() ),
true );
518 showMessageLater(
_(
"Graphics error during recovery" ),
_(
"Unknown exception during backend switch" ),
534 if(
m_gal->IsContextLocked() )
538 if( !IsShownOnScreen() )
542 if( !
m_gal->IsResetSettled() )
548 wxLogTrace(
traceGalContext, wxS(
"Rebuilding canvas %p after GPU reset, repeated %d" ),
this,
551 bool rebuilt =
false;
566 static bool s_notified =
false;
568 wxLogTrace(
traceGalContext, wxS(
"Canvas %p falling back to software rendering" ),
this );
575 showMessageLater(
_(
"The graphics driver keeps resetting, falling back to software rendering" ),
576 wxEmptyString,
false );
590 [parent, aTitle, aDetail, aError]()
607 auto packet = std::make_unique<KIGFX::FRAME_PACKET>();
610 packet->drawDesc.reuseStaticFBO =
true;
613 galModern->PopulateCameraUBOs( packet->drawDesc );
614 galModern->PopulateCursorUBO( packet->drawDesc );
619 packet->staticChanged =
true;
620 packet->dynamicChanged =
true;
624 packet->inputSerial =
s_inputSerial.load( std::memory_order_relaxed );
633 wxLogTrace(
traceRhi, wxS(
"DrawPanel: DoRePaint SKIP (mutex locked)" ) );
637 std::lock_guard<std::mutex> lock(
m_refreshMutex, std::adopt_lock );
645 wxLogTrace(
traceRhi, wxS(
"DrawPanel: DoRePaint SKIP (hidden) windowId=%u" ),
m_windowId );
666 abandonRhiCanvas(
_(
"The graphics device was lost and could not be restored." ) );
671 if( !
m_gal->IsInitialized() || !
m_gal->IsVisible() ||
m_gal->IsContextLocked() )
673 wxLogTrace(
traceRhi, wxS(
"DrawPanel: DoRePaint SKIP (init=%d vis=%d locked=%d)" ),
674 m_gal->IsInitialized(),
m_gal->IsVisible(),
m_gal->IsContextLocked() );
680 wxLogTrace(
traceRhi, wxS(
"DrawPanel: DoRePaint SKIP (already drawing)" ) );
695 if(
Pgm().GetCommonSettings()->m_Appearance.show_scrollbars )
698#ifdef KICAD_GAL_PROFILE
699 latencyProbeZoomToRender.Checkpoint(
"do-repaint-start");
704 ( *m_PaintEventCounter )++;
713 PROF_TIMER cntCtx(
"view-context-create",
false);
714 PROF_TIMER cntCtxDestroy(
"view-context-destroy",
false);
715 PROF_TIMER cntRedraw(
"view-redraw-rects",
false);
717 bool isDirty =
false;
732 bool viewDirty =
m_view->IsDirty();
734 bool hasPendingItemUpdates =
m_view->HasPendingItemUpdates();
739 if( aAllowSkip && !viewDirty && !cursorMoved && !hasPendingItemUpdates )
745 if( hasPendingItemUpdates )
753 catch( std::out_of_range& err )
757 wxLogTrace(
traceDrawPanel, wxS(
"Out of Range error: %s" ), err.what() );
759 catch( std::runtime_error& err )
764 wxLogTrace(
traceDrawPanel, wxS(
"Runtime error during UpdateItems: %s" ),
770 viewDirty =
m_view->IsDirty();
775 if( aAllowSkip && !viewDirty && !cursorMoved )
792 m_view->SyncRetainedScene();
798 &&
m_view->IsCameraDirtyOnly()
799 && !
m_gal->HasStaticRebuildPending()
800 &&
m_gal->GetGridSources().empty();
805 m_gal->DrawCursor( cursorPos );
823 m_gal->DrawCursor( cursorPos );
825 if( galModern->SyncScene() )
834 auto packet = std::make_unique<KIGFX::FRAME_PACKET>();
836 packet->drawDesc.reuseStaticFBO =
false;
840 galModern->PopulateCameraUBOs( packet->drawDesc );
841 galModern->PopulateCursorUBO( packet->drawDesc );
848 packet->staticDrawDesc.reuseStaticFBO =
false;
849 packet->dynamicDrawDesc.reuseDynamicFBO =
false;
850 galModern->PopulateCameraUBOs( packet->staticDrawDesc );
851 galModern->PopulateCameraUBOs( packet->dynamicDrawDesc );
853 packet->staticChanged =
true;
854 packet->dynamicChanged =
true;
868 packet->inputSerial =
s_inputSerial.load( std::memory_order_relaxed );
896 throw std::runtime_error(
"Could not make the OpenGL context current" );
910 m_gal->ClearScreen();
917 m_gal->ClearScreen();
921 if(
m_gal->HasStaticRebuildPending() )
934 ||
m_gal->RefillsNonCachedTargets() )
946 m_gal->DrawCursor( cursorPos );
948 #ifdef KICAD_GAL_PROFILE
949 latencyProbeZoomToRender.Checkpoint(
"do-repaint-pre-ctx-destroy");
953 cntCtxDestroy.
Start();
957 cntCtxDestroy.
Stop();
959#ifdef KICAD_GAL_PROFILE
960 latencyProbeZoomToRender.Checkpoint(
"do-repaint-ctx-done");
974 auto packet = std::make_unique<KIGFX::FRAME_PACKET>();
976 packet->drawDesc = galModern->GetDrawDesc();
981 galModern->PopulateCursorUBO( packet->drawDesc );
983 packet->staticDrawDesc = galModern->GetStaticDrawDesc();
984 packet->dynamicDrawDesc = galModern->GetDynamicDrawDesc();
987 packet->staticDrawDesc.supersampleFactor = packet->drawDesc.supersampleFactor;
988 packet->dynamicDrawDesc.supersampleFactor = packet->drawDesc.supersampleFactor;
990 packet->staticChanged = galModern->TakeStaticChanged();
991 packet->dynamicChanged =
true;
993 if( packet->staticChanged )
1004 packet->inputSerial =
s_inputSerial.load( std::memory_order_relaxed );
1015 catch( std::exception& err )
1017 wxLogTrace(
traceDrawPanel, wxS(
"DoRePaint exception: %s" ), err.what() );
1032#ifdef KICAD_GAL_PROFILE
1045#ifdef KICAD_GAL_PROFILE
1046 wxLogTrace(
traceGalProfile,
"%s", latencyProbeZoomToRender.to_string() );
1047 latencyProbeRepaintToMotion.Reset();
1048 latencyProbeRepaintToMotion.Checkpoint(
"repaint-done");
1061 wxSize clientSize = GetClientSize();
1063 if( clientSize.x > 0 && clientSize.y > 0 &&
m_view
1077 m_gal->ComputeWorldScreenMatrix();
1087 double scale = 1.0 / std::max( fabs( vsize.
x / screenSize.
x ),
1088 fabs( vsize.
y / screenSize.
y ) );
1092 if( !std::isfinite(
scale ) )
1102 double margin_scale_factor = aMarginScale.value_or( GetClientSize().y < 768 ? 1.10 : 1.04 );
1131 wxSize size = GetClientSize();
1136 return wxSize( std::max( 10, size.x +
pad ), std::max( 10, size.y +
pad ) );
1143 if(
m_gal->IsContextLocked() )
1149 if( !
m_gal->IsContextValid() )
1163 if( !aForce &&
ToVECTOR2I( clientSize ) ==
m_gal->GetScreenPixelSize() )
1166 m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
1168 wxWindow* backendWindow =
dynamic_cast<wxWindow*
>(
m_gal );
1176 static_cast<float>( GetContentScaleFactor() ) );
1181 float dpiScale =
static_cast<float>( GetContentScaleFactor() );
1183 static_cast<uint32_t
>( clientSize.y ),
1193 m_view->MarkGeometryDirty();
1203 std::vector<wxRect> rects;
1204 int infobarsBottom = 0;
1206 for( wxWindow* child : GetChildren() )
1208 if(
dynamic_cast<WX_INFOBAR*
>( child ) && child->IsShown() )
1210 rects.push_back( child->GetRect() );
1211 infobarsBottom = std::max( infobarsBottom, child->GetRect().GetBottom() + 1 );
1221 inset = infobarsBottom;
1233 cairoGal->SetOverlayExclusions( rects );
1245 const auto now = std::chrono::steady_clock::now();
1253 m_refreshRate = reported >= 24.0 && reported <= 1000.0 ?
static_cast<float>( reported ) : 0.0f;
1263 auto now = std::chrono::steady_clock::now();
1265 bool galInitialized =
m_gal &&
m_gal->IsInitialized();
1271 int minPeriodMs = 3;
1273 if( galInitialized &&
m_gal->GetSwapInterval() == 0 )
1276 int refreshHz = displayHz > 0.0f ?
KiROUND( displayHz ) : 60;
1280 minPeriodMs = 1000 / refreshHz;
1283 if(
delta >= minPeriodMs )
1298 wxLogTrace(
traceRhi, wxS(
"DrawPanel: ForceRefresh windowId=%u drawEnabled=%d "
1299 "IsShown=%d IsShownOnScreen=%d galInit=%d" ),
1319 else if( IsShownOnScreen() )
1430 m_view->UpdateAllLayersColor();
1436 m_view->ClearTopLayers();
1437 m_view->SetTopLayer( aLayer );
1438 m_view->UpdateAllLayersOrder();
1445 return static_cast<GAL_TYPE>( aStoredCanvasType );
1461 bool grid_visibility =
m_gal ?
m_gal->GetGridVisibility() :
true;
1462 double worldUnitLength =
m_gal ?
m_gal->GetWorldUnitLength() : 0.0;
1481 if( errormsg.empty() )
1490 showMessageLater(
_(
"Could not use OpenGL, falling back to software rendering" ), errormsg,
1523 wxLogTrace(
traceRhi, wxS(
"DrawPanel: render thread acquired" ) );
1544 galModern->SetPersistentTargets(
true );
1554 wxLogTrace(
traceRhi, wxS(
"DrawPanel: windowId=%u swapchainCtrl created" ),
m_windowId );
1582 catch( std::runtime_error& err )
1601 showMessageLater(
_(
"Could not use OpenGL, falling back to software rendering" ),
1602 wxString( err.what() ),
false );
1604 catch( std::runtime_error& )
1615 showMessageLater(
_(
"Error switching GAL backend" ), wxString( err.what() ),
true );
1637 if( worldUnitLength > 0.0 )
1638 m_gal->SetWorldUnitLength( worldUnitLength );
1644 galModern->
SetDpiScale(
static_cast<float>( GetContentScaleFactor() ) );
1649 wxSize clientSize = GetClientSize();
1652 clientSize.x = std::max( 10, clientSize.x +
pad );
1653 clientSize.y = std::max( 10, clientSize.y +
pad );
1654 m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() );
1657 m_gal->SetGridOrigin( grid_origin );
1659 if( grid_size.
x > 0 && grid_size.
y > 0 )
1660 m_gal->SetGridSize( grid_size );
1662 m_gal->SetGridVisibility( grid_visibility );
1683 for( wxWindow* child : GetChildren() )
1685 if( child !=
dynamic_cast<wxWindow*
>(
m_gal ) )
1695 wxLogTrace(
traceRhi, wxS(
"DrawPanel: backend %d view centre (%.17g, %.17g) scale %.17g screen %dx%d" ),
1697 m_gal->GetScreenPixelSize().x,
m_gal->GetScreenPixelSize().y );
1713 :
dynamic_cast<wxWindow*
>(
m_gal );
1739 catch(
const std::runtime_error& e )
1771 if( shouldSetFocus )
1791 if( shouldSetFocus )
1818 wxLogTrace(
traceRhi, wxS(
"DrawPanel: onIdle refresh windowId=%u IsShown=%d "
1819 "IsShownOnScreen=%d" ),
1851 wxLogTrace(
traceRhi, wxS(
"DrawPanel: onShowEvent windowId=%u show=%d IsShown=%d "
1852 "IsShownOnScreen=%d galInit=%d" ),
1853 m_windowId, aEvent.IsShown(), IsShown(), IsShownOnScreen(),
1857 if( !IsShownOnScreen() )
1884 m_gal->SetNativeCursorStyle( aCursor, hidpi );
1887#if wxCHECK_VERSION( 3, 3, 0 )
BASE_SCREEN class implementation.
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
VECTOR2D m_ScrollCenter
Current scroll center point in logical units.
constexpr size_type GetWidth() const
constexpr Vec Centre() const
constexpr size_type GetHeight() const
constexpr const SizeVec & GetSize() const
static const WX_CURSOR_TYPE GetCursor(KICURSOR aCursorType, bool aHiDPI=false)
Get a cursor bundle (wx 3.3+) or appropriate cursor (older versions)
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
double GetContentScaleFactor() const override
Get the content scale factor, which may be different from the scale factor on some platforms.
FRAME_T GetFrameType() const
void Unregister(EDA_CURSOR_OWNER *aOwner)
static EDA_CURSOR_BROADCASTER & Instance()
void NotifyCursorEntered(EDA_CURSOR_OWNER *aEnteredOwner)
Hide the cursor in every registered owner other than aEnteredOwner.
void Register(EDA_CURSOR_OWNER *aOwner)
The base class for create windows for drawing purpose.
static bool CanvasFailed(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvas)
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
static void SetCanvasFailed(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvas)
Keep every frame off a canvas for this session without changing the saved preference.
std::unique_ptr< PROF_COUNTER > m_PaintEventCounter
bool m_cursorVisibilityDirty
The cursor was shown or hidden since the last repaint.
void onIdleAwaitShow(wxIdleEvent &aEvent)
EDA_DRAW_FRAME * m_edaFrame
Parent EDA_DRAW_FRAME (if available)
static GAL_TYPE CanvasAfterFailure(GAL_TYPE aFailedCanvasType)
Return the canvas that takes over from one that could not be used.
virtual void OnShow()
Called when the window is shown for the first time.
void onLostFocus(wxFocusEvent &aEvent)
static constexpr GAL_TYPE GAL_FALLBACK
std::unique_ptr< KIGFX::PAINTER > m_painter
Contains information about how to draw items using GAL.
RHI_NATIVE_WINDOW_HANDLE m_cachedNativeHandle
Fetching the handle forces a display-server flush, so it is cached between realizations and fetched a...
bool m_rebuiltAfterReset
The GAL was rebuilt after a GPU reset and has not completed a frame yet.
void onSize(wxSizeEvent &aEvent)
bool m_pendingResize
Set when a size change could not be applied because the GL context was unavailable.
bool m_needIdleRefresh
True when canvas needs to be refreshed from idle handler.
bool IsDialogPreview() const
std::unique_ptr< KIGFX::SWAPCHAIN_CONTROLLER > m_swapchainCtrl
bool abandonRhiCanvas(const wxString &aDetail)
Leave the RHI canvas for GAL_FALLBACK after its device could not be created or restored.
virtual void SetHighContrastLayer(int aLayer)
Take care of display settings for the given layer to be displayed in high contrast mode.
void SetCursorInCanvas(bool aCursorInCanvas)
Set whether the mouse cursor is inside the drawing canvas.
int m_overlayInsetTop
Rows at the top of the panel left to the infobars where the backend window would hide them.
bool m_stealsFocus
Flag to indicate whether the panel should take focus at certain times (when moused over,...
virtual BOX2I GetDefaultViewBBox() const
Return the bounding box of the view that should be used if model is not valid.
KIGFX::GAL_DISPLAY_OPTIONS & m_options
void StopDrawing()
Prevent the GAL canvas from further drawing until it is recreated or StartDrawing() is called.
KIGFX::RHI_LINE_PIPELINE_KIND m_linePipelineKind
Fixed in the constructor from the parent frame's editor.
static KIGFX::VC_SETTINGS GetVcSettings()
Gets a populated View Controls settings object dervived from our program settings.
static void NoteInput()
Count an input so the frame that answers it is never held back by the display-rate limit.
std::unique_ptr< KIGFX::FRAME_MAILBOX > m_frameMailbox
Delivers frame packets to the render thread.
virtual void SetTopLayer(int aLayer)
Move the selected layer to the top, so it is displayed above all others.
KIGFX::FRAME_DRAW_DESC m_lastFullStaticDesc
Draw descriptors of the last full redraw, reused by frames that need no new geometry.
void presentFrame()
Present the most recently submitted frame packet.
void ClearDebugOverlay()
Clear the contents of the debug overlay and removes it from the VIEW.
virtual KIGFX::VIEW * GetView() const
Return a pointer to the KIGFX::VIEW instance used in the panel.
static int ScreenSizePad(GAL_TYPE aBackend)
Return how many pixels larger than the client area a backend's GAL is made.
void ForceRefresh()
Force a redraw.
bool recoverFromGalError(const std::exception &aErr)
void ResizeGal(bool aForce=false)
Resize the GAL to the current client size of this panel.
bool m_drawing
True if GAL is currently redrawing the view.
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
EDA_DRAW_PANEL_GAL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
Create a drawing panel that is contained inside aParentWindow.
std::chrono::steady_clock::time_point m_lastRepaintStart
Timestamp of the last repaint start.
void onRefreshTimer(wxTimerEvent &aEvent)
float displayRefreshRate()
Refresh rate in Hz of the display showing the canvas, or 0 when unknown.
void releaseCachedNativeWindowHandle()
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
virtual void onPaint(wxPaintEvent &WXUNUSED(aEvent))
bool m_lostFocus
Flag to indicate that focus should be regained on the next mouse event.
std::unique_ptr< KIGFX::RHI_DEVICE_PROXY > m_deviceProxy
The UI thread's access to the device.
static bool IsAccelerated(GAL_TYPE aCanvasType)
True for a canvas drawn on the GPU, which keeps cached layers between frames.
wxSize backendScreenSize() const
The padded size of the backend window, which sits below the top overlay inset.
std::chrono::steady_clock::time_point m_lastRepaintEnd
Timestamp of the last repaint end.
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_debugOverlay
Optional overlay for drawing transient debug objects.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
bool m_needsExternalRenderingSetup
True until the first paint completes the deferred GTK drawing suppression.
wxTimer m_refreshTimer
Timer to prevent too-frequent refreshing.
TOOL_DISPATCHER * m_eventDispatcher
Processes and forwards events to tools.
wxWindow * m_parent
Pointer to the parent window.
@ GAL_TYPE_OPENGL
OpenGL implementation.
@ GAL_TYPE_MODERN
RHI implementation, Vulkan or Metal on macOS.
@ GAL_TYPE_CAIRO
Cairo implementation.
@ GAL_TYPE_NONE
GAL not used (the legacy wxDC engine is used)
virtual void beforeRedraw()
Hook for subclasses to update view items whose inputs nothing else tracks.
bool m_awaitingShow
A hidden canvas whose GAL is not ready yet waits for idle instead of polling.
KIGFX::FRAME_DRAW_DESC m_lastFullDynamicDesc
void teardownModernRenderInfra()
Stop the RHI render thread and release its swapchain, mailbox and buffers.
virtual void prepareGridSources()
Hook for subclasses to push per-frame grid sources onto the GAL.
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
bool m_MouseCapturedLost
used on wxMSW: true after a wxEVT_MOUSE_CAPTURE_LOST was received false after the mouse is recaptured...
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
bool m_cursorInCanvas
True while the mouse cursor is inside the drawing canvas.
const RHI_NATIVE_WINDOW_HANDLE & getCachedNativeWindowHandle()
Return the native window handle for RHI surface creation, or an invalid handle until the window is re...
void onIdle(wxIdleEvent &aEvent)
void UpdateTouchpadGestureHandler()
Apply the current native touchpad gesture preference to the active backend window.
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
void UpdateOverlayExclusions()
Tell the backend which areas of this panel are covered by an overlaid infobar.
float m_refreshRate
What displayRefreshRate() last asked the window system.
void onEnter(wxMouseEvent &aEvent)
void submitCachedScene()
Submit the last full scene again with the current camera and cursor, keeping all targets.
uint32_t m_windowId
Routes this window's work on the render thread.
void showMessageLater(const wxString &aTitle, const wxString &aDetail, bool aError)
Show a recovery message once the current event finishes.
std::unique_ptr< KIPLATFORM::UI::TOUCHPAD_GESTURE_HANDLER > m_touchpadGestureHandler
uint64_t m_staticEpoch
Content generations of the static and dynamic pools last submitted, see FRAME_PACKET.
void RequestRefresh()
Make sure a refresh gets done on the next idle event if it hasn't already.
int m_contextBindFailures
Consecutive frames dropped because the GL context could not be made current.
std::shared_ptr< KIGFX::RENDER_THREAD > m_renderThread
The render thread that owns the RHI device, shared by every canvas, see GAL_MODERN::AcquireRenderThre...
std::mutex m_refreshMutex
Blocks multiple calls to the draw.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Switch method of rendering graphics.
void StartDrawing()
Begin drawing if it was stopped previously.
static GAL_TYPE ResolveStoredCanvasType(int aStoredCanvasType)
Convert a stored canvas type setting into a backend that can actually be used.
bool DoRePaint(bool aAllowSkip=true)
Repaint the canvas, and fix scrollbar cursors.
void OnEvent(wxEvent &aEvent)
Used to forward events to the canvas from popups, etc.
bool m_recoveryAttempted
Set after a GPU recovery attempt to prevent infinite retry loops.
bool m_drawingEnabled
Flag that determines if VIEW may use GAL for redrawing the screen.
std::shared_ptr< KIGFX::VIEW_OVERLAY > DebugOverlay()
Create an overlay for rendering debug graphics.
KIGFX::AUTOMATIC_FIT m_automaticFit
What the last ZoomToFit() left, refitted on a resize until the view is zoomed or panned.
void onShowEvent(wxShowEvent &aEvent)
bool handleContextLoss()
Replace a GAL whose context was destroyed by a GPU reset.
static constexpr bool GAL_FALLBACK_AVAILABLE
GAL_TYPE m_backend
Currently used GAL.
std::chrono::steady_clock::time_point m_refreshRateAsked
void ZoomToFit(const BOX2I &aBox, std::optional< double > aMarginScale=std::nullopt)
Scale and centre the view on aBox, and fit it again whenever the canvas changes size until something ...
VECTOR2D m_lastCursorPosition
Last cursor position sent to GAL for drawing.
bool m_hasLastFullDrawDesc
bool GetScreenshot(wxImage &aDstImage)
Capture the current canvas contents into aDstImage.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
bool m_refreshDeferred
The refresh timer was armed by Refresh() for a repaint it postponed.
GAL that turns drawing commands into instanced primitives for the RHI device.
void SetCentringPad(int aPad)
The other canvases lay the view out this many pixels larger than the client area.
void SetRenderThread(RENDER_THREAD *aThread)
Render thread used for fence-based synchronization.
static uint32_t AllocateWindowId()
static std::shared_ptr< RENDER_THREAD > AcquireRenderThread(bool aEnableValidation)
Return the render thread every RHI canvas in the process shares, starting it on first use and replaci...
void SetDpiScale(float aScale)
Backing-store scale factor, 2.0 on Retina.
Abstract interface for drawing on a 2D-surface.
Raised when a GPU buffer allocation is predicted to exceed the available video memory.
OpenGL implementation of the Graphics Abstraction Layer.
static wxString CheckFeatures(GAL_DISPLAY_OPTIONS &aOptions)
Check OpenGL features.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void ClearHighContrastLayers()
Clear the list of active layers.
virtual const COLOR4D & GetGridColor()=0
Return current grid color settings.
virtual const COLOR4D & GetBackgroundColor() const =0
Return current background color settings.
void SetLayerIsHighContrast(int aLayerId, bool aEnabled=true)
Set the specified layer as high-contrast.
virtual const COLOR4D & GetCursorColor()=0
Return current cursor color settings.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
const VECTOR2D & GetCenter() const
Return the center point of this VIEW (in world space coordinates).
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
static const wxEventType EVT_REFRESH_MOUSE
Event that forces mouse move event in the dispatcher (eg.
virtual COMMON_SETTINGS * GetCommonSettings() const
A small class to help profiling.
void Stop()
Save the time when this function was called, and set the counter stane to stop.
void Start()
Start or restart the counter.
RAII class that sets an value at construction and resets it to the original value at destruction.
A modified version of the wxInfoBar class that allows us to:
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
static RHI_NATIVE_WINDOW_HANDLE GetNativeWindowHandle(wxWindow *aWindow)
static constexpr int MAX_CONTEXT_BIND_RETRIES
Frames to drop before giving up on the GL context and letting the backend recover.
static void ApplyAntialiasingMode(KIGFX::FRAME_DRAW_DESC &aDesc, KIGFX::GAL_ANTIALIASING_MODE aMode)
static std::atomic< uint64_t > s_inputSerial
static KIGFX::RHI_LINE_PIPELINE_KIND DetermineLinePipelineKind(const EDA_DRAW_FRAME *aFrame)
@ FRAME_SCH_SYMBOL_EDITOR
const wxChar *const traceGalContext
Flag to enable debug output of GAL context binding.
const wxChar *const traceRhi
Flag to enable debug output of the RHI rendering backend.
static const wxChar traceDrawPanel[]
Flag to enable drawing panel debugging output.
const wxChar *const traceGalProfile
Flag to enable debug output of GAL performance profiling.
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
GAL_CONTEXT_LOSS
State of a canvas' rendering context after a GPU reset.
@ REPEATED
Contexts keep being lost; stop using this backend.
@ RECOVERABLE
Context was lost; rebuild the canvas.
@ ALL
All except INITIAL_ADD.
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
KICOMMON_API bool IsInputControlFocused(wxWindow *aFocus=nullptr)
Check if a input control has focus.
KICOMMON_API bool IsModalDialogFocused()
PGM_BASE & Pgm()
The global program "get" accessor.
RHI_DISPLAY_TYPE
Matches KIPLATFORM::UI::NATIVE_DISPLAY_TYPE as reported by GetNativeWindowHandles().
int canvas_type
EDA_DRAW_PANEL_GAL::GAL_TYPE_* value, see gal_options_panel.cpp.
GPU geometry of one frame, built by GAL_MODERN after EndDrawing() and passed through the FRAME_MAILBO...
RHI_LINE_PIPELINE_KIND linePipelineKind
uint32_t supersampleFactor
Layer FBO scale that the present blit downsamples.
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
MOUSE_DRAG_ACTION m_dragLeft
bool m_horizontalPan
Enable horizontal panning with the horizontal scroll/trackpad input.
bool m_scrollReversePanH
Whether to invert the scroll wheel movement for horizontal pan.
bool m_autoPanSettingEnabled
Flag for turning on autopanning.
bool m_focusFollowSchPcb
Flag for automatic focus switching between Schematic and PCB editors.
float m_autoPanAcceleration
How fast does panning accelerate when approaching the window boundary.
MOUSE_DRAG_ACTION m_dragMiddle
int m_zoomSpeed
Zoom speed for the non-accelerating zoom controller.
int m_scrollModifierZoom
What modifier key to enable zoom with the (vertical) scroll wheel.
int m_scrollModifierPanH
What modifier key to enable horizontal pan with the (vertical) scroll wheel.
bool m_warpCursor
If the cursor is allowed to be warped.
MOUSE_DRAG_ACTION m_dragRight
bool m_scrollReverseZoom
Whether to invert the scroll wheel movement for zoom.
int m_motionPanModifier
What modifier key pans the view when the mouse moves with it held.
bool m_zoomAcceleration
Enable the accelerating zoom controller.
bool m_zoomSpeedAuto
When true, ignore zoom_speed and pick a platform-specific default.
int m_scrollModifierPanV
What modifier key to enable vertical with the (vertical) scroll wheel.
Platform-agnostic wrapper for a native window handle.
RHI_DISPLAY_TYPE displayType
bool IsValid() const
A handle is usable only once the window is realized.
DATABASE_CONNECTION dc(odbcBackend(cs))
wxString result
Test unit parsing edge cases and error handling.
wxLogTrace helper definitions.
VECTOR2< double > VECTOR2D
VECTOR2I ToVECTOR2I(const wxSize &aSize)
WX_VIEW_CONTROLS class definition.