From 62c28ce0d35201dbc15c0cc9699c215d09451ecf Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 12 Jun 2014 16:37:05 -0700 Subject: [PATCH] Avoid pointless repaints of the grid when seeking video Keep track of which lines are displayed on the current video frame so that video seeks only have to repaint the grid when the set actually changes. Speeds up video playback on non-fbf stuff by ~15%. --- src/base_grid.cpp | 29 ++++++++++++++++++++++++++--- src/base_grid.h | 4 ++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/base_grid.cpp b/src/base_grid.cpp index 3fa9b776a..0a6265cc1 100644 --- a/src/base_grid.cpp +++ b/src/base_grid.cpp @@ -98,7 +98,7 @@ BaseGrid::BaseGrid(wxWindow* parent, agi::Context *context) , context(context) , columns(GetGridColumns()) , columns_visible(OPT_GET("Subtitle/Grid/Column")->GetListBool()) -, seek_listener(context->videoController->AddSeekListener([&] { Refresh(false); })) +, seek_listener(context->videoController->AddSeekListener(&BaseGrid::OnSeek, this)) { scrollBar->SetScrollbar(0,10,100,10); @@ -276,6 +276,24 @@ void BaseGrid::SelectRow(int row, bool addToSelected, bool select) { } } +void BaseGrid::OnSeek() { + int lines = GetClientSize().GetHeight() / lineHeight + 1; + lines = mid(0, lines, GetRows() - yPos); + + auto it = begin(visible_rows); + for (int i : boost::irange(yPos, yPos + lines)) { + if (IsDisplayed(index_line_map[i])) { + if (it == end(visible_rows) || *it != i) { + Refresh(false); + return; + } + ++it; + } + } + if (it != end(visible_rows)) + Refresh(false); +} + void BaseGrid::OnPaint(wxPaintEvent &) { // Find which columns need to be repainted std::vector paint_columns; @@ -357,6 +375,7 @@ void BaseGrid::OnPaint(wxPaintEvent &) { const auto active_line = context->selectionController->GetActiveLine(); auto const& selection = context->selectionController->GetSelectedSet(); + visible_rows.clear(); for (int i : agi::util::range(nDraw)) { wxBrush color = row_colors.Default; @@ -369,8 +388,12 @@ void BaseGrid::OnPaint(wxPaintEvent &) { color = row_colors.Selection; else if (curDiag->Comment) color = row_colors.Comment; - else if (OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame")->GetBool() && IsDisplayed(curDiag)) - color = row_colors.Visible; + + if (OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame")->GetBool() && IsDisplayed(curDiag)) { + if (color == row_colors.Default) + color = row_colors.Visible; + visible_rows.push_back(i + yPos); + } dc.SetBrush(color); // Draw row background color diff --git a/src/base_grid.h b/src/base_grid.h index 71d1c2f6a..75d65993b 100644 --- a/src/base_grid.h +++ b/src/base_grid.h @@ -57,6 +57,9 @@ class BaseGrid final : public wxWindow { int active_row = -1; + /// Rows which are visible on the current video frame + std::vector visible_rows; + agi::Context *context; ///< Associated project context std::vector> columns; @@ -95,6 +98,7 @@ class BaseGrid final : public wxWindow { void OnSize(wxSizeEvent &event); void OnSubtitlesCommit(int type); void OnActiveLineChanged(AssDialogue *); + void OnSeek(); void AdjustScrollbar(); void SetColumnWidths();