mirror of https://github.com/odrling/Aegisub
Prevent event queue flooded by wxEVT_PAINT by moving some repaint request to OnIdle
This commit is contained in:
parent
7b69476b5b
commit
e481d033cb
|
@ -125,6 +125,7 @@ BEGIN_EVENT_TABLE(BaseGrid,wxWindow)
|
||||||
EVT_KEY_DOWN(BaseGrid::OnKeyDown)
|
EVT_KEY_DOWN(BaseGrid::OnKeyDown)
|
||||||
EVT_CHAR_HOOK(BaseGrid::OnCharHook)
|
EVT_CHAR_HOOK(BaseGrid::OnCharHook)
|
||||||
EVT_MENU_RANGE(MENU_SHOW_COL,MENU_SHOW_COL+15,BaseGrid::OnShowColMenu)
|
EVT_MENU_RANGE(MENU_SHOW_COL,MENU_SHOW_COL+15,BaseGrid::OnShowColMenu)
|
||||||
|
EVT_IDLE(BaseGrid::OnIdle)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
void BaseGrid::OnSubtitlesCommit(int type) {
|
void BaseGrid::OnSubtitlesCommit(int type) {
|
||||||
|
@ -136,8 +137,12 @@ void BaseGrid::OnSubtitlesCommit(int type) {
|
||||||
Refresh(false);
|
Refresh(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type & AssFile::COMMIT_DIAG_TIME)
|
if (type & AssFile::COMMIT_DIAG_TIME) {
|
||||||
Refresh(false);
|
// Dragging start / end time in audio display can generate lots of commit in a short period of time.
|
||||||
|
// On the other hand, GDI painting time depends on area, and BaseGrid typically is very large. Therefore repainting BaseGrid can be expensive.
|
||||||
|
// To prevent GUI lag / FPS drop caused by frequent repaint of BaseGrid, we do not call Refresh(false) here. Instead, we set the refresh_on_idle flag, and only repaint BaseGrid when idle.
|
||||||
|
refresh_on_idle = true;
|
||||||
|
}
|
||||||
else if (type & AssFile::COMMIT_DIAG_TEXT) {
|
else if (type & AssFile::COMMIT_DIAG_TEXT) {
|
||||||
for (auto const& rect : text_refresh_rects)
|
for (auto const& rect : text_refresh_rects)
|
||||||
RefreshRect(rect, false);
|
RefreshRect(rect, false);
|
||||||
|
@ -263,6 +268,13 @@ void BaseGrid::OnSeek() {
|
||||||
Refresh(false);
|
Refresh(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseGrid::OnIdle(wxIdleEvent&) {
|
||||||
|
if (refresh_on_idle) {
|
||||||
|
refresh_on_idle = false;
|
||||||
|
Refresh(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BaseGrid::OnPaint(wxPaintEvent &) {
|
void BaseGrid::OnPaint(wxPaintEvent &) {
|
||||||
// Find which columns need to be repainted
|
// Find which columns need to be repainted
|
||||||
std::vector<char> paint_columns;
|
std::vector<char> paint_columns;
|
||||||
|
|
|
@ -71,6 +71,8 @@ class BaseGrid final : public wxWindow {
|
||||||
|
|
||||||
std::vector<wxRect> text_refresh_rects;
|
std::vector<wxRect> text_refresh_rects;
|
||||||
|
|
||||||
|
bool refresh_on_idle = false;
|
||||||
|
|
||||||
/// Cached brushes used for row backgrounds
|
/// Cached brushes used for row backgrounds
|
||||||
struct {
|
struct {
|
||||||
wxBrush Default;
|
wxBrush Default;
|
||||||
|
@ -93,6 +95,7 @@ class BaseGrid final : public wxWindow {
|
||||||
|
|
||||||
void OnContextMenu(wxContextMenuEvent &evt);
|
void OnContextMenu(wxContextMenuEvent &evt);
|
||||||
void OnHighlightVisibleChange(agi::OptionValue const& opt);
|
void OnHighlightVisibleChange(agi::OptionValue const& opt);
|
||||||
|
void OnIdle(wxIdleEvent&);
|
||||||
void OnKeyDown(wxKeyEvent &event);
|
void OnKeyDown(wxKeyEvent &event);
|
||||||
void OnCharHook(wxKeyEvent &event);
|
void OnCharHook(wxKeyEvent &event);
|
||||||
void OnMouseEvent(wxMouseEvent &event);
|
void OnMouseEvent(wxMouseEvent &event);
|
||||||
|
|
|
@ -105,7 +105,7 @@ VideoDisplay::VideoDisplay(wxToolBar *toolbar, bool freeSize, wxComboBox *zoomBo
|
||||||
});
|
});
|
||||||
|
|
||||||
Bind(wxEVT_PAINT, std::bind(&VideoDisplay::Render, this));
|
Bind(wxEVT_PAINT, std::bind(&VideoDisplay::Render, this));
|
||||||
Bind(wxEVT_UPDATE_UI, &VideoDisplay::OnUpdateUIEvent, this);
|
Bind(wxEVT_IDLE, &VideoDisplay::OnIdle, this);
|
||||||
Bind(wxEVT_SIZE, &VideoDisplay::OnSizeEvent, this);
|
Bind(wxEVT_SIZE, &VideoDisplay::OnSizeEvent, this);
|
||||||
Bind(wxEVT_CONTEXT_MENU, &VideoDisplay::OnContextMenu, this);
|
Bind(wxEVT_CONTEXT_MENU, &VideoDisplay::OnContextMenu, this);
|
||||||
Bind(wxEVT_ENTER_WINDOW, &VideoDisplay::OnMouseEvent, this);
|
Bind(wxEVT_ENTER_WINDOW, &VideoDisplay::OnMouseEvent, this);
|
||||||
|
@ -158,7 +158,7 @@ void VideoDisplay::Render() {
|
||||||
render_requested = true;
|
render_requested = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoDisplay::OnUpdateUIEvent(wxUpdateUIEvent&) {
|
void VideoDisplay::OnIdle(wxIdleEvent&) {
|
||||||
if (render_requested)
|
if (render_requested)
|
||||||
DoRender();
|
DoRender();
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ class VideoDisplay final : public wxGLCanvas {
|
||||||
/// @brief Recalculate video positioning and scaling when the available area or zoom changes
|
/// @brief Recalculate video positioning and scaling when the available area or zoom changes
|
||||||
void OnSizeEvent(wxSizeEvent &event);
|
void OnSizeEvent(wxSizeEvent &event);
|
||||||
void OnContextMenu(wxContextMenuEvent&);
|
void OnContextMenu(wxContextMenuEvent&);
|
||||||
void OnUpdateUIEvent(wxUpdateUIEvent& event);
|
void OnIdle(wxIdleEvent&);
|
||||||
void DoRender();
|
void DoRender();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue