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%.
This commit is contained in:
Thomas Goyne 2014-06-12 16:37:05 -07:00
parent 633fa0e4d7
commit 62c28ce0d3
2 changed files with 30 additions and 3 deletions

View File

@ -98,7 +98,7 @@ BaseGrid::BaseGrid(wxWindow* parent, agi::Context *context)
, context(context) , context(context)
, columns(GetGridColumns()) , columns(GetGridColumns())
, columns_visible(OPT_GET("Subtitle/Grid/Column")->GetListBool()) , 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); 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 &) { 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;
@ -357,6 +375,7 @@ void BaseGrid::OnPaint(wxPaintEvent &) {
const auto active_line = context->selectionController->GetActiveLine(); const auto active_line = context->selectionController->GetActiveLine();
auto const& selection = context->selectionController->GetSelectedSet(); auto const& selection = context->selectionController->GetSelectedSet();
visible_rows.clear();
for (int i : agi::util::range(nDraw)) { for (int i : agi::util::range(nDraw)) {
wxBrush color = row_colors.Default; wxBrush color = row_colors.Default;
@ -369,8 +388,12 @@ void BaseGrid::OnPaint(wxPaintEvent &) {
color = row_colors.Selection; color = row_colors.Selection;
else if (curDiag->Comment) else if (curDiag->Comment)
color = row_colors.Comment; color = row_colors.Comment;
else if (OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame")->GetBool() && IsDisplayed(curDiag))
if (OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame")->GetBool() && IsDisplayed(curDiag)) {
if (color == row_colors.Default)
color = row_colors.Visible; color = row_colors.Visible;
visible_rows.push_back(i + yPos);
}
dc.SetBrush(color); dc.SetBrush(color);
// Draw row background color // Draw row background color

View File

@ -57,6 +57,9 @@ class BaseGrid final : public wxWindow {
int active_row = -1; int active_row = -1;
/// Rows which are visible on the current video frame
std::vector<int> visible_rows;
agi::Context *context; ///< Associated project context agi::Context *context; ///< Associated project context
std::vector<std::unique_ptr<GridColumn>> columns; std::vector<std::unique_ptr<GridColumn>> columns;
@ -95,6 +98,7 @@ class BaseGrid final : public wxWindow {
void OnSize(wxSizeEvent &event); void OnSize(wxSizeEvent &event);
void OnSubtitlesCommit(int type); void OnSubtitlesCommit(int type);
void OnActiveLineChanged(AssDialogue *); void OnActiveLineChanged(AssDialogue *);
void OnSeek();
void AdjustScrollbar(); void AdjustScrollbar();
void SetColumnWidths(); void SetColumnWidths();