Explorar o código

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 %!s(int64=5) %!d(string=hai) anos
pai
achega
7cc9a18c39
Modificáronse 1 ficheiros con 8 adicións e 5 borrados
  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();
     invalidate_cursor();
 
 
     for (u16 row = 0; row < m_terminal.rows(); ++row) {
     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);
         auto& line = m_terminal.line(row);
         bool has_only_one_background_color = line.has_only_one_background_color();
         bool has_only_one_background_color = line.has_only_one_background_color();
         if (m_visual_beep_timer.is_active())
         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)
         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) {
         for (u16 column = 0; column < m_terminal.columns(); ++column) {
             char ch = line.characters[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())
             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;
     Rect rect;
     for (int i = 0; i < m_terminal.rows(); ++i) {
     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));
             rect = rect.united(row_rect(i));
+            m_terminal.line(i).dirty = false;
+        }
     }
     }
     update(rect);
     update(rect);
 }
 }
@@ -247,8 +252,6 @@ void TerminalWidget::flush_dirty_lines()
 void TerminalWidget::force_repaint()
 void TerminalWidget::force_repaint()
 {
 {
     m_needs_background_fill = true;
     m_needs_background_fill = true;
-    for (int i = 0; i < m_terminal.rows(); ++i)
-        m_terminal.line(i).dirty = true;
     update();
     update();
 }
 }