[vte/wip/sixels: 108/111] build: Add sixel option
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte/wip/sixels: 108/111] build: Add sixel option
- Date: Sat, 8 Aug 2020 18:43:03 +0000 (UTC)
commit 41837a868c23933c05a5e3c0aabec95fdc07c3c3
Author: Christian Persch <chpe src gnome org>
Date: Sat Aug 8 20:42:49 2020 +0200
build: Add sixel option
For 0.62, put the sixel code behind a build option, in case it
has problems and needs to be disabled for stable.
meson.build | 2 ++
meson_options.txt | 7 +++++
src/meson.build | 37 +++++++++++++---------
src/parser-string.hh | 4 +++
src/ring.cc | 38 +++++++++++++++++++++--
src/ring.hh | 31 +++++++++++--------
src/vte.cc | 87 ++++++++++++++++++++++++++++++++++------------------
src/vtegtk.cc | 16 ++++++++++
src/vteinternal.hh | 3 +-
src/vteseq.cc | 18 ++++++-----
10 files changed, 176 insertions(+), 67 deletions(-)
---
diff --git a/meson.build b/meson.build
index 11ca2f9a..b77d2a18 100644
--- a/meson.build
+++ b/meson.build
@@ -124,6 +124,7 @@ config_h.set('WITH_A11Y', get_option('a11y'))
config_h.set('WITH_FRIBIDI', get_option('fribidi'))
config_h.set('WITH_GNUTLS', get_option('gnutls'))
config_h.set('WITH_ICU', get_option('icu'))
+config_h.set('WITH_SIXEL', get_option('sixel'))
ver = glib_min_req_version.split('.')
config_h.set('GLIB_VERSION_MIN_REQUIRED', '(G_ENCODE_VERSION(' + ver[0] + ',' + ver[1] + '))')
@@ -505,6 +506,7 @@ output += ' GTK+ 4.0: ' + get_option('gtk4').to_string() + '\n'
output += ' ICU: ' + get_option('icu').to_string() + '\n'
output += ' GIR: ' + get_option('gir').to_string() + '\n'
output += ' systemd: ' + systemd_dep.found().to_string() + '\n'
+output += ' SIXEL: ' + get_option('sixel').to_string() + '\n'
output += ' Vala: ' + get_option('vapi').to_string() + '\n'
output += '\n'
output += ' Prefix: ' + get_option('prefix') + '\n'
diff --git a/meson_options.txt b/meson_options.txt
index f8143f77..d37be0ab 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -85,6 +85,13 @@ option(
description: 'Enable legacy charset support using ICU',
)
+option(
+ 'sixel',
+ type: 'boolean',
+ value: false,
+ description: 'Enable SIXEL support',
+)
+
option(
'_systemd',
type: 'boolean',
diff --git a/src/meson.build b/src/meson.build
index 7901342d..365cf485 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -87,6 +87,13 @@ regex_sources = files(
'regex.hh'
)
+sixel_sources = files(
+ 'image.cc',
+ 'image.hh',
+ 'sixelparser.cc',
+ 'sixelparser.hh',
+)
+
systemd_sources = files(
'systemd.cc',
'systemd.hh',
@@ -114,8 +121,6 @@ libvte_common_sources = debug_sources + glib_glue_sources + libc_glue_sources +
'fonts-pangocairo.cc',
'fonts-pangocairo.hh',
'gobject-glue.hh',
- 'image.cc',
- 'image.hh',
'keymap.cc',
'keymap.h',
'minifont.cc',
@@ -128,8 +133,6 @@ libvte_common_sources = debug_sources + glib_glue_sources + libc_glue_sources +
'ring.hh',
'ringview.cc',
'ringview.hh',
- 'sixelparser.cc',
- 'sixelparser.hh',
'spawn.cc',
'spawn.hh',
'utf8.cc',
@@ -169,6 +172,10 @@ if get_option('icu')
libvte_common_sources += icu_sources
endif
+if get_option('sixel')
+ libvte_common_sources += sixel_sources
+endif
+
if systemd_dep.found()
libvte_common_sources += systemd_sources
endif
@@ -463,17 +470,19 @@ test_refptr = executable(
install: false,
)
-test_sixel_sources = files(
- 'sixel-test.cc',
-)
+if get_option('sixel')
+ test_sixel_sources = files(
+ 'sixel-test.cc',
+ )
-test_sixel = executable(
- 'test-sixel',
- sources: test_sixel_sources,
- dependencies: [glib_dep,],
- include_directories: top_inc,
- install: false,
-)
+ test_sixel = executable(
+ 'test-sixel',
+ sources: test_sixel_sources,
+ dependencies: [glib_dep,],
+ include_directories: top_inc,
+ install: false,
+ )
+endif
test_tabstops_sources = files(
'tabstops-test.cc',
diff --git a/src/parser-string.hh b/src/parser-string.hh
index d14375e0..746051e4 100644
--- a/src/parser-string.hh
+++ b/src/parser-string.hh
@@ -35,12 +35,16 @@ typedef struct vte_seq_string_t {
#define VTE_SEQ_STRING_DEFAULT_CAPACITY (1 << 7) /* must be power of two */
+#ifdef WITH_SIXEL
/* This needs to be somewhat large for the time being; it accommodates inline
* graphics formats (e.g. sixels), and there is no provision for parsing
* those incrementally yet. 8M characters is typically enough for an
* RLE-incompressible 256-color 1920x1080 image. Since VTE seqs store 32 bits
* per character, this corresponds to a 32MiB buffer. */
#define VTE_SEQ_STRING_MAX_CAPACITY (1 << 23)
+#else
+#define VTE_SEQ_STRING_MAX_CAPACITY (1 << 12)
+#endif
/*
* vte_seq_string_init:
diff --git a/src/ring.cc b/src/ring.cc
index 0ffa2e9a..ae86d23e 100644
--- a/src/ring.cc
+++ b/src/ring.cc
@@ -25,6 +25,9 @@
#include "vterowdata.hh"
#include <string.h>
+
+#ifdef WITH_SIXEL
+
#include <new>
/* We should be able to hold a single fullscreen 4K image at most.
@@ -35,6 +38,8 @@
* of potential issues related to algorithmic complexity. */
#define IMAGE_FAST_COUNT_MAX 4096
+#endif /* WITH_SIXEL */
+
/*
* Copy the common attributes from VteCellAttr to VteStreamCellAttr or vice versa.
*/
@@ -45,7 +50,10 @@ _attrcpy (void *dst, void *src)
}
using namespace vte::base;
+
+#ifdef WITH_SIXEL
using namespace vte::image;
+#endif
/*
* VteRing: A buffer ring
@@ -96,29 +104,33 @@ Ring::Ring(row_t max_rows,
auto empty_str = g_string_new_len("", 0);
g_ptr_array_add(m_hyperlinks, empty_str);
- m_image_by_top_map = new (std::nothrow) std::map<gint, Image *>();
+#ifdef WITH_SIXEL
+ m_image_by_top_map = new (std::nothrow) std::map<int, Image *>();
m_image_priority_map = new (std::nothrow) std::map<int, Image *>();
m_next_image_priority = 0;
m_image_fast_memory_used = 0;
+#endif
validate();
}
Ring::~Ring()
{
- auto image_map = m_image_by_top_map;
-
for (size_t i = 0; i <= m_mask; i++)
_vte_row_data_fini (&m_array[i]);
g_free (m_array);
+#ifdef WITH_SIXEL
/* Clear images */
+ auto image_map = m_image_by_top_map;
+
for (auto it = image_map->begin (); it != image_map->end (); ++it)
delete it->second;
image_map->clear();
delete m_image_by_top_map;
delete m_image_priority_map;
+#endif /* WITH_SIXEL */
if (m_has_streams) {
g_object_unref (m_attr_stream);
@@ -215,6 +227,8 @@ Ring::hyperlink_maybe_gc(row_t increment)
hyperlink_gc();
}
+#ifdef WITH_SIXEL
+
void
Ring::image_gc_region()
{
@@ -312,6 +326,8 @@ Ring::rewrap_images_in_range(std::map<int,Image*>::iterator &it,
return true;
}
+#endif /* WITH_SIXEL */
+
/*
* Find existing idx for the hyperlink or allocate a new one.
*
@@ -706,7 +722,9 @@ Ring::reset_streams(row_t position)
Ring::row_t
Ring::reset()
{
+#ifdef WITH_SIXEL
auto image_map = m_image_by_top_map;
+#endif
_vte_debug_print (VTE_DEBUG_RING, "Reseting the ring at %lu.\n", m_end);
@@ -714,6 +732,7 @@ Ring::reset()
m_start = m_writable = m_end;
m_cached_row_num = (row_t)-1;
+#ifdef WITH_SIXEL
/* Clear images */
for (auto it = image_map->begin (); it != image_map->end (); ++it)
delete it->second;
@@ -721,6 +740,7 @@ Ring::reset()
m_image_priority_map->clear();
m_next_image_priority = 0;
m_image_fast_memory_used = 0;
+#endif
return m_end;
}
@@ -1305,7 +1325,9 @@ Ring::rewrap(column_t columns,
gsize paragraph_len; /* excluding trailing '\n' */
gsize attr_offset;
gsize old_ring_end;
+#ifdef WITH_SIXEL
auto image_it = m_image_by_top_map->begin();
+#endif
if (G_UNLIKELY(length() == 0))
return;
@@ -1441,8 +1463,10 @@ Ring::rewrap(column_t columns,
}
}
+#ifdef WITH_SIXEL
if (!rewrap_images_in_range(image_it,
new_record.text_start_offset, text_offset, new_row_index))
goto err;
+#endif
new_row_index++;
new_record.text_start_offset = text_offset;
@@ -1493,8 +1517,10 @@ Ring::rewrap(column_t columns,
}
}
+#ifdef WITH_SIXEL
if (!rewrap_images_in_range(image_it, new_record.text_start_offset,
paragraph_end_text_offset, new_row_index))
goto err;
+#endif
new_row_index++;
paragraph_start_text_offset = paragraph_end_text_offset;
@@ -1528,7 +1554,9 @@ Ring::rewrap(column_t columns,
g_free(marker_text_offsets);
g_free(new_markers);
+#ifdef WITH_SIXEL
rebuild_image_top_map();
+#endif
_vte_debug_print(VTE_DEBUG_RING, "Ring after rewrapping:\n");
validate();
@@ -1634,6 +1662,8 @@ Ring::write_contents(GOutputStream* stream,
return true;
}
+#ifdef WITH_SIXEL
+
/**
* Ring::append_image:
* @surface: A Cairo surface object
@@ -1666,3 +1696,5 @@ Ring::append_image (cairo_surface_t *surface, gint pixelwidth, gint pixelheight,
image_gc_region();
image_gc();
}
+
+#endif /* WITH_SIXEL */
diff --git a/src/ring.hh b/src/ring.hh
index ab1b58a4..85fd7236 100644
--- a/src/ring.hh
+++ b/src/ring.hh
@@ -27,10 +27,13 @@
#include "vterowdata.hh"
#include "vtestream.h"
+
+#ifdef WITH_SIXEL
#include "image.hh"
+#include <map>
+#endif
#include <type_traits>
-#include <map>
typedef struct _VteVisualPosition {
long row, col;
@@ -91,10 +94,6 @@ public:
VteRowData* insert(row_t position, guint8 bidi_flags);
VteRowData* append(guint8 bidi_flags);
void remove(row_t position);
- void append_image (cairo_surface_t *surface,
- gint pixelwidth, gint pixelheight,
- glong left, glong top,
- glong cell_width, glong cell_height);
void drop_scrollback(row_t position);
void set_visible_rows(row_t rows);
void rewrap(column_t columns,
@@ -104,8 +103,14 @@ public:
GCancellable* cancellable,
GError** error);
+#ifdef WITH_SIXEL
+ void append_image (cairo_surface_t *surface,
+ gint pixelwidth, gint pixelheight,
+ glong left, glong top,
+ glong cell_width, glong cell_height);
std::map<gint, vte::image::Image *> *m_image_by_top_map;
std::map<int, vte::image::Image *> *m_image_priority_map;
+#endif
private:
@@ -118,15 +123,8 @@ private:
inline VteRowData* get_writable_index(row_t position) const { return &m_array[position & m_mask]; }
void hyperlink_gc();
- void image_gc();
- void image_gc_region();
hyperlink_idx_t get_hyperlink_idx_no_update_current(char const* hyperlink);
- void unlink_image_from_top_map(vte::image::Image *image);
- void rebuild_image_top_map();
- bool rewrap_images_in_range(std::map<int,vte::image::Image*>::iterator &it,
- size_t text_start_ofs, size_t text_end_ofs, row_t new_row_index);
-
typedef struct _CellAttrChange {
gsize text_end_offset; /* offset of first character no longer using this attr */
VteStreamCellAttr attr;
@@ -243,10 +241,19 @@ private:
An idx is allocated on hover even if the cell is scrolled
out to the streams. */
row_t m_hyperlink_maybe_gc_counter{0}; /* Do a GC when it reaches 65536. */
+#ifdef WITH_SIXEL
/* Image bookkeeping */
+ void image_gc();
+ void image_gc_region();
+ void unlink_image_from_top_map(vte::image::Image *image);
+ void rebuild_image_top_map();
+ bool rewrap_images_in_range(std::map<int,vte::image::Image*>::iterator &it,
+ size_t text_start_ofs, size_t text_end_ofs, row_t new_row_index);
+
int m_next_image_priority;
unsigned int m_image_fast_memory_used;
+#endif /* WITH_SIXEL */
};
}; /* namespace base */
diff --git a/src/vte.cc b/src/vte.cc
index 54ff872b..f8592985 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -7745,8 +7745,10 @@ Terminal::Terminal(vte::platform::Widget* w,
save_cursor(&m_normal_screen);
save_cursor(&m_alternate_screen);
+#ifdef WITH_SIXEL
/* Initialize SIXEL color register */
sixel_parser_set_default_color(&m_sixel_state);
+#endif
/* Matching data. */
m_match_span.clear(); // FIXMEchpe unnecessary
@@ -8204,38 +8206,48 @@ Terminal::draw_cells(vte::view::DrawingContext::TextRequest* items,
else
rgb_from_index<4, 5, 4>(deco, dc);
- /* Paint the background. */
- i = 0;
- while (i < n) {
- xl = items[i].x;
- xr = items[i].x + items[i].columns * column_width;
- y = items[i].y;
- /* Items are not necessarily contiguous in LTR order.
- * Combine as long as they form a single visual run. */
- for (i++; i < n && items[i].y == y; i++) {
- if (G_LIKELY (items[i].x == xr)) {
- xr += items[i].columns * column_width; /* extend to the right */
- } else if (items[i].x + items[i].columns * column_width == xl) {
- xl = items[i].x; /* extend to the left */
- } else {
- break; /* break the run */
+#ifndef WITH_SIXEL
+ if (clear && (draw_default_bg || back != VTE_DEFAULT_BG)) {
+#else
+ {
+#endif
+ /* Paint the background. */
+ i = 0;
+ while (i < n) {
+ xl = items[i].x;
+ xr = items[i].x + items[i].columns * column_width;
+ y = items[i].y;
+ /* Items are not necessarily contiguous in LTR order.
+ * Combine as long as they form a single visual run. */
+ for (i++; i < n && items[i].y == y; i++) {
+ if (G_LIKELY (items[i].x == xr)) {
+ xr += items[i].columns * column_width; /* extend to the right */
+ } else if (items[i].x + items[i].columns * column_width == xl) {
+ xl = items[i].x; /* extend to the left */
+ } else {
+ break; /* break the run */
+ }
}
- }
- if (back == VTE_DEFAULT_BG) {
- /* Clear cells in order to properly overdraw images */
- m_draw.clear(xl,
- y,
- xr - xl, row_height,
- get_color(VTE_DEFAULT_BG), m_background_alpha);
- }
+#ifdef WITH_SIXEL
+ if (back == VTE_DEFAULT_BG) {
+ /* Clear cells in order to properly overdraw images */
+ m_draw.clear(xl,
+ y,
+ xr - xl, row_height,
+ get_color(VTE_DEFAULT_BG), m_background_alpha);
+ }
- if (clear && (draw_default_bg || back != VTE_DEFAULT_BG)) {
- m_draw.fill_rectangle(
- xl,
- y,
- xr - xl, row_height,
- &bg, VTE_DRAW_OPAQUE);
+ if (clear && (draw_default_bg || back != VTE_DEFAULT_BG)) {
+#else
+ {
+#endif
+ m_draw.fill_rectangle(
+ xl,
+ y,
+ xr - xl, row_height,
+ &bg, VTE_DRAW_OPAQUE);
+ }
}
}
@@ -8845,6 +8857,14 @@ Terminal::draw_rows(VteScreen *screen_,
nhilite = (nhyperlink && cell->attr.hyperlink_idx == m_hyperlink_hover_idx) ||
(!nhyperlink && regex_match_has_current() && m_match_span.contains(row,
lcol));
if (cell->c == 0 ||
+#ifndef WITH_SIXEL
+ ((cell->c == ' ' || cell->c == '\t') && // FIXME '\t' is newly added now,
double check
+ cell->attr.has_none(VTE_ATTR_UNDERLINE_MASK |
+ VTE_ATTR_STRIKETHROUGH_MASK |
+ VTE_ATTR_OVERLINE_MASK) &&
+ !nhyperlink &&
+ !nhilite) ||
+#endif
cell->attr.fragment() ||
cell->attr.invisible()) {
/* Skip empty or fragment cell, but erase on ' ' and '\t', since
@@ -9204,7 +9224,9 @@ Terminal::widget_draw(cairo_t *cr)
int allocated_width, allocated_height;
int extra_area_for_cursor;
bool text_blink_enabled_now;
+#ifdef WITH_SIXEL
VteRing *ring = m_screen->row_data;
+#endif
gint64 now = 0;
if (!gdk_cairo_get_clip_rectangle (cr, &clip_rect))
@@ -9232,8 +9254,8 @@ Terminal::widget_draw(cairo_t *cr)
get_color(VTE_DEFAULT_BG), m_background_alpha);
}
+#ifdef WITH_SIXEL
/* Draw images */
-
if (m_images_enabled) {
vte::grid::row_t top_row = first_displayed_row();
vte::grid::row_t bottom_row = last_displayed_row();
@@ -9257,6 +9279,7 @@ Terminal::widget_draw(cairo_t *cr)
image->paint (cr, x, y, m_cell_width, m_cell_height);
}
}
+#endif /* WITH_SIXEL */
/* Clip vertically, for the sake of smooth scrolling. We want the top and bottom paddings to be
unused.
* Don't clip horizontally so that antialiasing can legally overflow to the right padding. */
@@ -9941,8 +9964,12 @@ Terminal::reset(bool clear_tabstops,
m_mouse_smooth_scroll_delta = 0.;
/* Clear modifiers. */
m_modifiers = 0;
+
+#ifdef WITH_SIXEL
/* Reset SIXEL color register */
sixel_parser_set_default_color(&m_sixel_state);
+#endif
+
/* Reset the saved cursor. */
save_cursor(&m_normal_screen);
save_cursor(&m_alternate_screen);
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index 34cf2b72..4fd83b3a 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -1917,7 +1917,11 @@ vte_terminal_class_init(VteTerminalClass *klass)
*/
pspecs[PROP_SIXEL_ENABLED] =
g_param_spec_boolean ("sixel-enabled", NULL, NULL,
+#ifdef WITH_SIXEL
VTE_SIXEL_ENABLED_DEFAULT,
+#else
+ false,
+#endif
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY));
@@ -2053,6 +2057,12 @@ vte_get_features (void) noexcept
"+ICU"
#else
"-ICU"
+#endif
+ " "
+#ifdef WITH_SIXEL
+ "+SIXEL"
+#else
+ "-SIXEL"
#endif
#ifdef __linux__
" "
@@ -5584,10 +5594,12 @@ vte_terminal_set_sixel_enabled(VteTerminal *terminal,
gboolean enabled) noexcept
try
{
+#ifdef WITH_SIXEL
g_return_if_fail(VTE_IS_TERMINAL(terminal));
if (WIDGET(terminal)->set_sixel_enabled(enabled))
g_object_notify_by_pspec(G_OBJECT(terminal), pspecs[PROP_SIXEL_ENABLED]);
+#endif
}
catch (...)
{
@@ -5606,9 +5618,13 @@ gboolean
vte_terminal_get_sixel_enabled(VteTerminal *terminal) noexcept
try
{
+#ifdef WITH_SIXEL
g_return_val_if_fail(VTE_IS_TERMINAL(terminal), FALSE);
return WIDGET(terminal)->sixel_enabled();
+#else
+ return false;
+#endif
}
catch (...)
{
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 7ee44008..88c2fe40 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -1578,7 +1578,8 @@ public:
inline vte::grid::column_t get_cursor_column_unclamped() const;
inline void move_cursor_up(vte::grid::row_t rows);
inline void move_cursor_down(vte::grid::row_t rows);
- inline void erase_characters(long count, bool use_basic);
+ inline void erase_characters(long count,
+ bool use_basic = false);
inline void insert_blank_character();
template<unsigned int redbits, unsigned int greenbits, unsigned int bluebits>
diff --git a/src/vteseq.cc b/src/vteseq.cc
index 99edfb66..f2d1e524 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -945,16 +945,14 @@ Terminal::move_cursor_down(vte::grid::row_t rows)
}
void
-Terminal::erase_characters(long count, bool use_basic)
+Terminal::erase_characters(long count,
+ bool use_basic)
{
VteCell *cell;
- VteCell blank_cell;
long col, i;
ensure_cursor_is_onscreen();
- blank_cell = use_basic ? basic_cell : m_color_defaults;
-
/* Clear out the given number of characters. */
auto rowdata = ensure_row();
if (_vte_ring_next(m_screen->row_data) > m_screen->cursor.row) {
@@ -971,10 +969,10 @@ Terminal::erase_characters(long count, bool use_basic)
/* Replace this cell with the current
* defaults. */
cell = _vte_row_data_get_writable (rowdata, col);
- *cell = blank_cell;
+ *cell = use_basic ? basic_cell : m_color_defaults;
} else {
/* Add new cells until we have one here. */
- _vte_row_data_fill (rowdata, &blank_cell, col + 1);
+ _vte_row_data_fill (rowdata, use_basic ? &basic_cell :
&m_color_defaults, col + 1);
}
}
}
@@ -2379,7 +2377,11 @@ Terminal::DA1(vte::parser::Sequence const& seq)
if (seq.collect1(0, 0) != 0)
return;
- reply(seq, VTE_REPLY_DECDA1R, {65, 1, 9, 4});
+ reply(seq, VTE_REPLY_DECDA1R, {65, 1,
+#ifdef WITH_SIXEL
+ 4,
+#endif
+ 9});
}
void
@@ -4337,6 +4339,7 @@ Terminal::DECSIXEL(vte::parser::Sequence const& seq)
* References: VT330
*/
+#ifdef WITH_SIXEL
if (!m_sixel_enabled)
return;
@@ -4433,6 +4436,7 @@ Terminal::DECSIXEL(vte::parser::Sequence const& seq)
cursor_down(true);
}
}
+#endif /* WITH_SIXEL */
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]