Ver código fonte

Terminal: Only repaint the lines that actually changed

This optimization was broken since who-knows-when. Now we once again do
our best to only repaint the lines that had the "dirty" flag set.

This dramatically reduces the amount of work done by an idle Terminal
since the cursor blinking won't redraw the whole window anymore. :^)
Andreas Kling 5 anos atrás
pai
commit
7cc9a18c39
1 arquivos alterados com 8 adições e 5 exclusões
  1. 8 5
      Applications/Terminal/TerminalWidget.cpp

+ 8 - 5
Applications/Terminal/TerminalWidget.cpp

@@ -184,12 +184,15 @@ void TerminalWidget::paint_event(GPaintEvent& event)
     invalidate_cursor();
 
     for (u16 row = 0; row < m_terminal.rows(); ++row) {
+        auto row_rect = this->row_rect(row);
+        if (!event.rect().contains(row_rect))
+            continue;
         auto& line = m_terminal.line(row);
         bool has_only_one_background_color = line.has_only_one_background_color();
         if (m_visual_beep_timer.is_active())
-            painter.fill_rect(row_rect(row), Color::Red);
+            painter.fill_rect(row_rect, Color::Red);
         else if (has_only_one_background_color)
-            painter.fill_rect(row_rect(row), lookup_color(line.attributes[0].background_color).with_alpha(m_opacity));
+            painter.fill_rect(row_rect, lookup_color(line.attributes[0].background_color).with_alpha(m_opacity));
         for (u16 column = 0; column < m_terminal.columns(); ++column) {
             char ch = line.characters[column];
             bool should_reverse_fill_for_cursor_or_selection = (m_cursor_blink_state && m_in_active_window && row == m_terminal.cursor_row() && column == m_terminal.cursor_column())
@@ -238,8 +241,10 @@ void TerminalWidget::flush_dirty_lines()
     }
     Rect rect;
     for (int i = 0; i < m_terminal.rows(); ++i) {
-        if (m_terminal.line(i).dirty)
+        if (m_terminal.line(i).dirty) {
             rect = rect.united(row_rect(i));
+            m_terminal.line(i).dirty = false;
+        }
     }
     update(rect);
 }
@@ -247,8 +252,6 @@ void TerminalWidget::flush_dirty_lines()
 void TerminalWidget::force_repaint()
 {
     m_needs_background_fill = true;
-    for (int i = 0; i < m_terminal.rows(); ++i)
-        m_terminal.line(i).dirty = true;
     update();
 }