[vte/wip/egmont/bidi: 22/23] fine grained gtk invalidate, part 1
- From: Egmont Koblinger <egmontkob src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/wip/egmont/bidi: 22/23] fine grained gtk invalidate, part 1
- Date: Fri, 31 May 2019 13:05:13 +0000 (UTC)
commit 96603eddfb13f3bd3b65758738d9a3c0b620c062
Author: Egmont Koblinger <egmont gmail com>
Date: Wed May 29 14:34:34 2019 +0200
fine grained gtk invalidate, part 1
src/vte.cc | 126 +++++++++++++++++++++++++++++++++++++----------------
src/vteinternal.hh | 6 ++-
src/vteseq.cc | 24 +++++-----
3 files changed, 105 insertions(+), 51 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 9565f456..6768f22d 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -245,10 +245,22 @@ Terminal::cursor_is_onscreen() const noexcept
}
/* Note that end_row is inclusive. This is not as nice as end-exclusive,
- * but saves us from a +1 almost everywhere where this method is called. */
+ * but saves us from a +1 almost everywhere where this method is called.
+ *
+ * If @extend, the region is extended in both directions up to an explicit
+ * newline (or a safety limit) to invalidate entire paragraphs of text.
+ * This is to be used whenever the underlying data changes, because any such
+ * change might alter the desired BiDi, syntax highlighting etc. of all other
+ * rows of the involved paragraph(s).
+ *
+ * If not @extend, only the requested rows are invalidated. This is to be
+ * used when only the desired rendering changes but not the underlying data,
+ * e.g. moving or blinking cursor, highligthing with the mouse etc.
+ */
void
Terminal::invalidate_rows(vte::grid::row_t row_start,
- vte::grid::row_t row_end /* inclusive */)
+ vte::grid::row_t row_end /* inclusive */,
+ bool extend)
{
if (G_UNLIKELY (!widget_realized()))
return;
@@ -260,24 +272,57 @@ Terminal::invalidate_rows(vte::grid::row_t row_start,
return;
_vte_debug_print (VTE_DEBUG_UPDATES,
- "Invalidating rows %ld..%ld.\n",
- row_start, row_end);
+ "Invalidating rows %ld..%ld (extend: %s).\n",
+ row_start, row_end, extend ? "true" : "false");
_vte_debug_print (VTE_DEBUG_WORK, "?");
- // HACK for BiDi: Always invalidate everything.
- // In fact we'd need to invalidate the entire implicit paragraph.
- if (TRUE) {
- invalidate_all();
- return;
- }
+ if (extend) {
+ /* Scrolled back by so much that changes to the writable area
+ * may not affect the current viewport's rendering. */
+ if (m_screen->insert_delta - VTE_RINGVIEW_PARAGRAPH_LENGTH_MAX > last_displayed_row())
+ return;
+ } else {
+ /* Scrolled back, visible parts didn't change. */
+ if (row_start > last_displayed_row())
+ return;
+ }
- /* Scrolled back, visible parts didn't change. */
- if (row_start > last_displayed_row())
- return;
+ if (extend) {
+ /* Extending the start is a bit tricky.
+ *
+ * First extend it (towards lower numbered indices), but only up to
+ * insert_delta, which is still guaranteed to be in the ring's memory. */
+ while (row_start > m_screen->insert_delta) {
+ if (!m_screen->row_data->is_soft_wrapped(row_start - 1))
+ break;
+ row_start--;
+ }
+
+ /* If we haven't seen a newline yet, stop walking backwards row by row.
+ * This is because we might need to access row_stream in order to check
+ * its wrapped state, a way too expensive operation while processing
+ * incoming data. Let displaying do extra work instead.
+ * So just invalidate everything to the top. */
+ if (row_start < m_screen->insert_delta) {
+ row_start = first_displayed_row();
+ }
+
+ /* Extending the end is simple. Just walk until we go offscreen or
+ * find an explicit newline. */
+ while (row_end < last_displayed_row()) {
+ if (!m_screen->row_data->is_soft_wrapped(row_end))
+ break;
+ row_end++;
+ }
+
+ _vte_debug_print (VTE_DEBUG_UPDATES,
+ "Invalidating rows extended to %ld..%ld.\n",
+ row_start, row_end);
+ }
- /* Scrollbar is at default position, all the writable rows changed. */
- if (row_start == first_displayed_row() &&
- row_end - row_start + 1 == m_row_count) {
+ /* Recognize if we're already invalidating everything. */
+ if (row_start <= first_displayed_row() &&
+ row_end >= last_displayed_row()) {
invalidate_all();
return;
}
@@ -320,19 +365,21 @@ Terminal::invalidate_rows(vte::grid::row_t row_start,
/* Convenience method */
void
-Terminal::invalidate_row(vte::grid::row_t row)
+Terminal::invalidate_row(vte::grid::row_t row, bool extend)
{
- invalidate_rows(row, row);
+ invalidate_rows(row, row, extend);
}
+/* This is only used by the selection code, so no need to extend the area. */
void
Terminal::invalidate(vte::grid::span const& s)
{
if (!s.empty())
- invalidate_rows(s.start_row(), s.last_row());
+ invalidate_rows(s.start_row(), s.last_row(), false);
}
-/* Invalidates the symmetrical difference ("XOR" area) of the two spans */
+/* Invalidates the symmetrical difference ("XOR" area) of the two spans.
+ * This is only used by the selection code, so no need to extend the area. */
void
Terminal::invalidate_symmetrical_difference(vte::grid::span const& a, vte::grid::span const& b, bool block)
{
@@ -346,15 +393,18 @@ Terminal::invalidate_symmetrical_difference(vte::grid::span const& a, vte::grid:
if (block) {
/* We could optimize when the columns don't change, probably not worth it. */
invalidate_rows (std::min (a.start_row(), b.start_row()),
- std::max (a.last_row(), b.last_row()));
+ std::max (a.last_row(), b.last_row()),
+ false);
} else {
if (a.start() != b.start()) {
invalidate_rows (std::min (a.start_row(), b.start_row()),
- std::max (a.start_row(), b.start_row()));
+ std::max (a.start_row(), b.start_row()),
+ false);
}
if (a.end() != b.end()) {
invalidate_rows (std::min (a.last_row(), b.last_row()),
- std::max (a.last_row(), b.last_row()));
+ std::max (a.last_row(), b.last_row()),
+ false);
}
}
}
@@ -575,7 +625,7 @@ Terminal::invalidate_cursor_once(bool periodic)
_vte_debug_print(VTE_DEBUG_UPDATES,
"Invalidating cursor in row %ld.\n",
row);
- invalidate_row(row);
+ invalidate_row(row, false);
}
}
@@ -2697,7 +2747,7 @@ Terminal::cleanup_fragments(long start,
cell_end->c = ' ';
cell_end->attr.set_fragment(false);
cell_end->attr.set_columns(1);
- invalidate_row(m_screen->cursor.row);
+ invalidate_row(m_screen->cursor.row, false);
}
}
@@ -2721,7 +2771,7 @@ Terminal::cleanup_fragments(long start,
"Cleaning CJK left half at %ld\n",
col);
g_assert(start - col == 1);
- invalidate_row(m_screen->cursor.row);
+ invalidate_row(m_screen->cursor.row, false);
}
keep_going = FALSE;
}
@@ -2763,7 +2813,8 @@ Terminal::cursor_down(bool explicit_sequence)
/* Force the areas below the region to be
* redrawn -- they've moved. */
invalidate_rows(m_screen->cursor.row,
- m_screen->insert_delta + m_row_count - 1);
+ m_screen->insert_delta + m_row_count - 1,
+ true /* FIXME */);
/* Force scroll. */
adjust_adjustments();
} else {
@@ -2775,7 +2826,7 @@ Terminal::cursor_down(bool explicit_sequence)
ring_remove(start);
ring_insert(end, true);
/* Update the display. */
- invalidate_rows(start, end);
+ invalidate_rows(start, end, true /* FIXME */);
}
} else {
/* Scroll up with history. */
@@ -3054,7 +3105,7 @@ Terminal::insert_char(gunichar c,
done:
/* Signal that this part of the window needs drawing. */
if (G_UNLIKELY (invalidate_now)) {
- invalidate_row(m_screen->cursor.row);
+ invalidate_row(m_screen->cursor.row, true);
}
/* We added text, so make a note of it. */
@@ -3096,7 +3147,7 @@ Terminal::apply_bidi_attributes(vte::grid::row_t row, guint8 bidi_flags, guint8
rowdata->attr.bidi_flags &= ~bidi_flags_mask;
rowdata->attr.bidi_flags |= bidi_flags;
- invalidate_row(row);
+ invalidate_row(row, false /* ugly */);
if (!rowdata->attr.soft_wrapped)
return;
row++;
@@ -3770,7 +3821,7 @@ Terminal::process_incoming()
if (invalidated_text &&
(m_screen->cursor.row > bbox_bottom +
VTE_CELL_BBOX_SLACK ||
m_screen->cursor.row < bbox_top - VTE_CELL_BBOX_SLACK))
{
- invalidate_rows(bbox_top, bbox_bottom);
+ invalidate_rows(bbox_top, bbox_bottom, true);
bbox_bottom = -G_MAXINT;
bbox_top = G_MAXINT;
}
@@ -3823,7 +3874,7 @@ Terminal::process_incoming()
((new_in_scroll_region && !in_scroll_region) ||
(m_screen->cursor.row > bbox_bottom + VTE_CELL_BBOX_SLACK ||
m_screen->cursor.row < bbox_top - VTE_CELL_BBOX_SLACK))) {
- invalidate_rows(bbox_top, bbox_bottom);
+ invalidate_rows(bbox_top, bbox_bottom, true);
invalidated_text = FALSE;
bbox_bottom = -G_MAXINT;
bbox_top = G_MAXINT;
@@ -3885,21 +3936,21 @@ Terminal::process_incoming()
emit_pending_signals();
if (invalidated_text) {
- invalidate_rows(bbox_top, bbox_bottom);
+ invalidate_rows(bbox_top, bbox_bottom, true);
}
if ((saved_cursor.col != m_screen->cursor.col) ||
(saved_cursor.row != m_screen->cursor.row)) {
/* invalidate the old and new cursor positions */
if (saved_cursor_visible)
- invalidate_row(saved_cursor.row);
+ invalidate_row(saved_cursor.row, false);
invalidate_cursor_once();
check_cursor_blink();
/* Signal that the cursor moved. */
queue_cursor_moved();
} else if ((saved_cursor_visible != m_modes_private.DEC_TEXT_CURSOR()) ||
(saved_cursor_style != m_cursor_style)) {
- invalidate_row(saved_cursor.row);
+ invalidate_row(saved_cursor.row, false);
check_cursor_blink();
}
@@ -5904,7 +5955,7 @@ Terminal::hyperlink_invalidate_and_get_bbox(vte::base::Ring::hyperlink_idx_t idx
}
}
if (G_UNLIKELY (do_invalidate_row)) {
- invalidate_row(row);
+ invalidate_row(row, false);
}
}
}
@@ -6029,6 +6080,7 @@ Terminal::match_hilite_clear()
}
}
+/* This is only used by the dingu matching code, so no need to extend the area. */
void
Terminal::invalidate_match_span()
{
@@ -10361,7 +10413,7 @@ Terminal::select_text(vte::grid::column_t start_col,
widget_copy(VTE_SELECTION_PRIMARY, VTE_FORMAT_TEXT);
emit_selection_changed();
- invalidate_rows(start_row, end_row);
+ invalidate_rows(start_row, end_row, false);
}
void
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index c51af508..d6a01c02 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -665,9 +665,11 @@ public:
bool insert,
bool invalidate_now);
- void invalidate_row(vte::grid::row_t row);
+ void invalidate_row(vte::grid::row_t row,
+ bool extend);
void invalidate_rows(vte::grid::row_t row_start,
- vte::grid::row_t row_end /* inclusive */);
+ vte::grid::row_t row_end /* inclusive */,
+ bool extend);
void invalidate(vte::grid::span const& s);
void invalidate_symmetrical_difference(vte::grid::span const& a, vte::grid::span const& b, bool
block);
void invalidate_match_span();
diff --git a/src/vteseq.cc b/src/vteseq.cc
index 1a80ea74..ec3f4c40 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -317,7 +317,7 @@ Terminal::clear_current_line()
set_hard_wrapped(m_screen->cursor.row);
rowdata->attr.bidi_flags = get_bidi_flags();
/* Repaint this row. */
- invalidate_row(m_screen->cursor.row);
+ invalidate_row(m_screen->cursor.row, false /* FIXME */);
}
/* We've modified the display. Make a note of it. */
@@ -345,7 +345,7 @@ Terminal::clear_above_current()
set_hard_wrapped(i);
rowdata->attr.bidi_flags = get_bidi_flags();
/* Repaint the row. */
- invalidate_row(i);
+ invalidate_row(i, false /* FIXME */);
}
}
/* We've modified the display. Make a note of it. */
@@ -391,7 +391,7 @@ Terminal::scroll_text(vte::grid::row_t scroll_amount)
}
/* Update the display. */
- invalidate_rows(start, end);
+ invalidate_rows(start, end, true /* FIXME */);
/* Adjust the scrollbars if necessary. */
adjust_adjustments();
@@ -714,7 +714,7 @@ Terminal::clear_to_bol()
}
}
/* Repaint this row. */
- invalidate_row(m_screen->cursor.row);
+ invalidate_row(m_screen->cursor.row, true);
/* We've modified the display. Make a note of it. */
m_text_deleted_flag = TRUE;
@@ -771,7 +771,7 @@ Terminal::clear_below_current()
if (i > m_screen->cursor.row)
rowdata->attr.bidi_flags = get_bidi_flags();
/* Repaint this row. */
- invalidate_row(i);
+ invalidate_row(i, true /* FIXME */);
}
/* We've modified the display. Make a note of it. */
@@ -810,7 +810,7 @@ Terminal::clear_to_eol()
}
set_hard_wrapped(m_screen->cursor.row);
/* Repaint this row. */
- invalidate_row(m_screen->cursor.row);
+ invalidate_row(m_screen->cursor.row, true /* FIXME */);
}
/*
@@ -942,7 +942,7 @@ Terminal::delete_character()
}
set_hard_wrapped(m_screen->cursor.row);
/* Repaint this row. */
- invalidate_row(m_screen->cursor.row);
+ invalidate_row(m_screen->cursor.row, true /* FIXME */);
}
}
@@ -1000,7 +1000,7 @@ Terminal::erase_characters(long count)
}
}
/* Repaint this row. */
- invalidate_row(m_screen->cursor.row);
+ invalidate_row(m_screen->cursor.row, true);
}
/* We've modified the display. Make a note of it. */
@@ -1115,7 +1115,7 @@ Terminal::move_cursor_tab_forward(int count)
}
}
- invalidate_row(m_screen->cursor.row);
+ invalidate_row(m_screen->cursor.row, false);
m_screen->cursor.col = newcol;
}
@@ -1337,7 +1337,7 @@ Terminal::insert_lines(vte::grid::row_t param)
m_screen->cursor.col = 0;
/* Update the display. */
- invalidate_rows(row, end);
+ invalidate_rows(row, end, true /* FIXME */);
/* Adjust the scrollbars if necessary. */
adjust_adjustments();
/* We've modified the display. Make a note of it. */
@@ -1377,7 +1377,7 @@ Terminal::delete_lines(vte::grid::row_t param)
}
m_screen->cursor.col = 0;
/* Update the display. */
- invalidate_rows(row, end);
+ invalidate_rows(row, end, true /* FIXME */);
/* Adjust the scrollbars if necessary. */
adjust_adjustments();
/* We've modified the display. Make a note of it. */
@@ -6777,7 +6777,7 @@ Terminal::RI(vte::parser::Sequence const& seq)
set_hard_wrapped(end);
/* Update the display. */
- invalidate_rows(start, end);
+ invalidate_rows(start, end, true /* FIXME */);
} else {
/* Otherwise, just move the cursor up. */
m_screen->cursor.row--;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]