[vte/wip/sixels: 3/82] sixels: Make it build again.



commit e22905bad997b851fbcf92d1e00a878e8b15ddfb
Author: Hans Petter Jansson <hpj cl no>
Date:   Sat May 23 21:38:17 2020 +0200

    sixels: Make it build again.

 src/ring.cc   | 47 +++++++++++++++++-------------------
 src/ring.hh   | 27 ++++++++++++++++-----
 src/vte.cc    | 76 +++++++++++++++++++++++++++++------------------------------
 src/vtegtk.cc |  8 +++----
 src/vteseq.cc | 18 +++++++-------
 5 files changed, 93 insertions(+), 83 deletions(-)
---
diff --git a/src/ring.cc b/src/ring.cc
index 99ff8b76..c1ac3844 100644
--- a/src/ring.cc
+++ b/src/ring.cc
@@ -1509,8 +1509,7 @@ Ring::write_contents(GOutputStream* stream,
 }
 
 /**
- * _vte_ring_append_image:
- * @ring: a #VteRing
+ * Ring::append_image:
  * @surface: a Cairo surface object
  * @pixelwidth: image width in pixels
  * @pixelheight: image height in pixels
@@ -1522,23 +1521,20 @@ Ring::write_contents(GOutputStream* stream,
  * Append an image into the internal image list.
  */
 void
-_vte_ring_append_image (VteRing *ring, cairo_surface_t *surface, gint pixelwidth, gint pixelheight, glong 
left, glong top, glong width, glong height)
+Ring::append_image (cairo_surface_t *surface, gint pixelwidth, gint pixelheight, glong left, glong top, 
glong width, glong height)
 {
        using namespace vte::image;
        image_object *image;
-       auto image_map = ring->image_map;
        gulong char_width, char_height;
 
-       g_assert_true (image_map != NULL);
-
-       image = new (std::nothrow) image_object (surface, pixelwidth, pixelheight, left, top, width, height, 
ring->image_stream);
+       image = new (std::nothrow) image_object (surface, pixelwidth, pixelheight, left, top, width, height, 
m_image_stream);
        g_assert_true (image != NULL);
 
        char_width = pixelwidth / width;
        char_height = pixelwidth / height;
 
        /* composition */
-       for (auto it = image_map->lower_bound (top); it != image_map->end (); ++it) {
+       for (auto it = m_image_map->lower_bound (top); it != m_image_map->end (); ++it) {
                image_object *current = it->second;
 
                /* Combine two images if one's area includes another's area */
@@ -1553,11 +1549,11 @@ _vte_ring_append_image (VteRing *ring, cairo_surface_t *surface, gint pixelwidth
                         *  | :.........:  |
                         *  +--------------+
                         */
-                       image_map->erase (image->get_bottom ());
+                       m_image_map->erase (image->get_bottom ());
                        if (current->is_freezed())
-                               ring->image_offscreen_resource_counter -= current->resource_size ();
+                               m_image_offscreen_resource_counter -= current->resource_size ();
                        else
-                               ring->image_onscreen_resource_counter -= current->resource_size ();
+                               m_image_onscreen_resource_counter -= current->resource_size ();
                        delete current;
                } else if (current->includes (image)) {
                        /*
@@ -1571,13 +1567,13 @@ _vte_ring_append_image (VteRing *ring, cairo_surface_t *surface, gint pixelwidth
                         *  +--------------+
                         */
                        if (current->is_freezed()) {
-                               ring->image_offscreen_resource_counter -= current->resource_size ();
+                               m_image_offscreen_resource_counter -= current->resource_size ();
                                current->thaw ();
                        } else {
-                               ring->image_onscreen_resource_counter -= current->resource_size ();
+                               m_image_onscreen_resource_counter -= current->resource_size ();
                        }
                        current->combine (image, char_width, char_height);
-                       ring->image_onscreen_resource_counter += current->resource_size ();
+                       m_image_onscreen_resource_counter += current->resource_size ();
                        delete image;
                        goto end;
                }
@@ -1608,44 +1604,43 @@ _vte_ring_append_image (VteRing *ring, cairo_surface_t *surface, gint pixelwidth
                         *  +------------------+
                         */
                        image->unite (image, char_width, char_height);
-                       image_map->erase (current->get_bottom ());
+                       m_image_map->erase (current->get_bottom ());
                        if (current->is_freezed())
-                               ring->image_offscreen_resource_counter -= current->resource_size ();
+                               m_image_offscreen_resource_counter -= current->resource_size ();
                        else
-                               ring->image_onscreen_resource_counter -= current->resource_size ();
+                               m_image_onscreen_resource_counter -= current->resource_size ();
                        delete current;
                        goto end;
                }
        }
 
-register_to_map:
        /*
-        * Now register new image to the image_map container.
+        * Now register new image to the m_image_map container.
         * the key is bottom positon.
         *  +----------+
         *  |   new    |
         *  |          |
         *  +----------+ <- bottom position (key)
         */
-       image_map->insert (std::make_pair (image->get_bottom (), image));
-       ring->image_onscreen_resource_counter += image->resource_size ();
+       m_image_map->insert (std::make_pair (image->get_bottom (), image));
+       m_image_onscreen_resource_counter += image->resource_size ();
 end:
        /* noop */
        ;
 }
 
 void
-_vte_ring_shrink_image_stream (VteRing *ring)
+Ring::shrink_image_stream ()
 {
        using namespace vte::image;
        image_object *first_image;
 
-       if (ring->image_map->empty())
+       if (m_image_map->empty())
                return;
 
-       first_image = ring->image_map->begin()->second;
+       first_image = m_image_map->begin()->second;
 
        if (first_image->is_freezed ())
-               if (first_image->get_stream_position () > _vte_stream_tail (ring->image_stream))
-                       _vte_stream_advance_tail (ring->image_stream, first_image->get_stream_position ());
+               if (first_image->get_stream_position () > _vte_stream_tail (m_image_stream))
+                       _vte_stream_advance_tail (m_image_stream, first_image->get_stream_position ());
 }
diff --git a/src/ring.hh b/src/ring.hh
index 87b73645..0330858e 100644
--- a/src/ring.hh
+++ b/src/ring.hh
@@ -27,8 +27,10 @@
 
 #include "vterowdata.hh"
 #include "vtestream.h"
+#include "vteimage.h"
 
 #include <type_traits>
+#include <map>
 
 typedef struct _VteVisualPosition {
        long row, col;
@@ -89,6 +91,8 @@ 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 width, glong height);
+        void shrink_image_stream ();
         void drop_scrollback(row_t position);
         void set_visible_rows(row_t rows);
         void rewrap(column_t columns,
@@ -98,6 +102,22 @@ public:
                             GCancellable* cancellable,
                             GError** error);
 
+        /* FIXME-hpj: These should be private, but are being accessed from the Terminal class for now:
+         *
+         * >>> */
+
+       bool m_has_streams;
+
+       row_t m_max;
+       row_t m_start{0};
+        row_t m_end{0};
+
+        std::map<gint, vte::image::image_object *> *m_image_map;
+        gulong m_image_onscreen_resource_counter;
+        gulong m_image_offscreen_resource_counter;
+
+        /* <<< */
+
 private:
 
         #ifdef VTE_DEBUG
@@ -183,10 +203,6 @@ private:
                       char const** hyperlink);
         void reset_streams(row_t position);
 
-       row_t m_max;
-       row_t m_start{0};
-        row_t m_end{0};
-
        /* Writable */
        row_t m_writable{0};
         row_t m_mask{31};
@@ -206,8 +222,7 @@ private:
          *    if nonempty, it actually contains the ID and URI separated with a semicolon. Not NUL 
terminated.
          *  - 2 bytes repeating attr.hyperlink_length so that we can walk backwards.
          */
-       bool m_has_streams;
-       VteStream *m_attr_stream, *m_text_stream, *m_row_stream;
+       VteStream *m_attr_stream, *m_text_stream, *m_row_stream, *m_image_stream;
        size_t m_last_attr_text_start_offset{0};
        VteCellAttr m_last_attr;
        GString *m_utf8_buffer;
diff --git a/src/vte.cc b/src/vte.cc
index 2d7d56d1..d4491ea0 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -4231,10 +4231,10 @@ Terminal::feed_child_binary(std::string_view const& data)
 }
 
 void
-VteTerminalPrivate::maybe_remove_images ()
+Terminal::maybe_remove_images ()
 {
        VteRing *ring = m_screen->row_data;
-       auto image_map = ring->image_map;
+       auto image_map = ring->m_image_map;
        vte::image::image_object *image;
 
        auto it = image_map->begin();
@@ -4245,28 +4245,28 @@ VteTerminalPrivate::maybe_remove_images ()
                image = it->second;
 
                /* break if the image is still in scrollback area */
-               if (image->get_bottom () >= ring->start)
+               if (image->get_bottom () >= (glong) ring->m_start)
                        break;
 
                /* otherwise, delete it */
                if (image->is_freezed ())
-                       ring->image_offscreen_resource_counter -= image->resource_size ();
+                       ring->m_image_offscreen_resource_counter -= image->resource_size ();
                else
-                       ring->image_onscreen_resource_counter -= image->resource_size ();
+                       ring->m_image_onscreen_resource_counter -= image->resource_size ();
                image_map->erase (image->get_bottom ());
                delete image;
                _vte_debug_print (VTE_DEBUG_IMAGE,
                                  "deleted, offscreen: %zu\n",
-                                 ring->image_offscreen_resource_counter);
+                                 ring->m_image_offscreen_resource_counter);
        }
 
        /* step 2. If the resource amount of freezed images (serialized into VteBoa)
         * exceeds the upper limit, remove images from oldest.
         */
-       if (ring->image_offscreen_resource_counter > m_freezed_image_limit) {
+       if (ring->m_image_offscreen_resource_counter > m_freezed_image_limit) {
                _vte_debug_print (VTE_DEBUG_IMAGE,
                                  "checked, offscreen: %zu, max: %zu\n",
-                                 ring->image_offscreen_resource_counter,
+                                 ring->m_image_offscreen_resource_counter,
                                  m_freezed_image_limit);
                while (it != image_map->end()) {
                        image = it->second;
@@ -4275,33 +4275,33 @@ VteTerminalPrivate::maybe_remove_images ()
                        /* remove */
                        image_map->erase (image->get_bottom ());
                        if (image->is_freezed ())
-                               ring->image_offscreen_resource_counter -= image->resource_size ();
+                               ring->m_image_offscreen_resource_counter -= image->resource_size ();
                        else
-                               ring->image_onscreen_resource_counter -= image->resource_size ();
+                               ring->m_image_onscreen_resource_counter -= image->resource_size ();
                        _vte_debug_print (VTE_DEBUG_IMAGE,
                                          "deleted, offscreen: %zu\n",
-                                         ring->image_offscreen_resource_counter);
+                                         ring->m_image_offscreen_resource_counter);
                        delete image;
 
                        /* break if the resource amount becomes less than limit */
-                       if (ring->image_offscreen_resource_counter <= m_freezed_image_limit)
+                       if (ring->m_image_offscreen_resource_counter <= m_freezed_image_limit)
                                break;
                }
        }
 
        /* step 3. shrink image stream with calling _vte_stream_advance_tail() */
-       if (ring->has_streams)
-               _vte_ring_shrink_image_stream (ring);
+       if (ring->m_has_streams)
+               ring->shrink_image_stream ();
 }
 
 void
-VteTerminalPrivate::freeze_hidden_images_before_view_area (double start_pos, double end_pos)
+Terminal::freeze_hidden_images_before_view_area (double start_pos, double end_pos)
 {
        VteRing *ring = m_screen->row_data;
-       auto image_map = ring->image_map;
+       auto image_map = ring->m_image_map;
        /* for images before view area */
        vte::grid::row_t top_of_view = (vte::grid::row_t)start_pos;
-       typedef std::remove_pointer<decltype(ring->image_map)>::type map_t;
+       typedef std::remove_pointer<decltype(ring->m_image_map)>::type map_t;
 
        /* iterate from new to old */
        for (auto it = map_t::reverse_iterator (image_map->lower_bound (top_of_view)); it != image_map->rend 
(); ++it) {
@@ -4309,22 +4309,22 @@ VteTerminalPrivate::freeze_hidden_images_before_view_area (double start_pos, dou
                if (image->get_bottom () + 1 < end_pos)
                        break;
                if (! image->is_freezed ()) {
-                       ring->image_onscreen_resource_counter -= image->resource_size ();
+                       ring->m_image_onscreen_resource_counter -= image->resource_size ();
                        image->freeze ();
-                       ring->image_offscreen_resource_counter += image->resource_size ();
+                       ring->m_image_offscreen_resource_counter += image->resource_size ();
                        _vte_debug_print (VTE_DEBUG_IMAGE,
                                          "freezed, onscreen: %zu, offscreen: %zu\n",
-                                         ring->image_onscreen_resource_counter,
-                                         ring->image_offscreen_resource_counter);
+                                         ring->m_image_onscreen_resource_counter,
+                                         ring->m_image_offscreen_resource_counter);
                }
        }
 }
 
 void
-VteTerminalPrivate::freeze_hidden_images_after_view_area (double start_pos, double end_pos)
+Terminal::freeze_hidden_images_after_view_area (double start_pos, double end_pos)
 {
        VteRing *ring = m_screen->row_data;
-       auto image_map = ring->image_map;
+       auto image_map = ring->m_image_map;
        vte::grid::row_t bottom_of_view = (vte::grid::row_t)(start_pos + m_row_count);
 
        /* for images after view area */
@@ -4333,13 +4333,13 @@ VteTerminalPrivate::freeze_hidden_images_after_view_area (double start_pos, doub
                if (image->get_top () < end_pos + m_row_count)
                        break;
                if (image->get_top () > bottom_of_view && ! image->is_freezed ()) {
-                       ring->image_onscreen_resource_counter -= image->resource_size ();
+                       ring->m_image_onscreen_resource_counter -= image->resource_size ();
                        image->freeze ();
-                       ring->image_offscreen_resource_counter += image->resource_size ();
+                       ring->m_image_offscreen_resource_counter += image->resource_size ();
                        _vte_debug_print (VTE_DEBUG_IMAGE,
                                          "freezed, onscreen: %zu, offscreen: %zu\n",
-                                         ring->image_onscreen_resource_counter,
-                                         ring->image_offscreen_resource_counter);
+                                         ring->m_image_onscreen_resource_counter,
+                                         ring->m_image_offscreen_resource_counter);
                }
        }
 }
@@ -7505,10 +7505,8 @@ Terminal::set_cell_height_scale(double scale)
 }
 
 bool
-VteTerminalPrivate::set_freezed_image_limit(gulong limit)
+Terminal::set_freezed_image_limit(gulong limit)
 {
-        g_assert(limit >= 0);
-
         m_freezed_image_limit = limit;
 
         return true;
@@ -7678,7 +7676,7 @@ Terminal::screen_set_size(VteScreen *screen_,
 }
 
 bool
-VteTerminalPrivate::set_sixel_enabled(gboolean enabled)
+Terminal::set_sixel_enabled(bool enabled)
 {
         m_sixel_enabled = enabled;
 
@@ -9342,7 +9340,7 @@ Terminal::widget_draw(cairo_t *cr)
         int allocated_width, allocated_height;
         int extra_area_for_cursor;
         bool text_blink_enabled_now;
-        Ring *ring = m_screen->row_data;
+        VteRing *ring = m_screen->row_data;
         gint64 now = 0;
 
         if (!gdk_cairo_get_clip_rectangle (cr, &clip_rect))
@@ -9374,24 +9372,24 @@ Terminal::widget_draw(cairo_t *cr)
        if (m_sixel_enabled) {
                vte::grid::row_t top_row = first_displayed_row();
                vte::grid::row_t bottom_row = last_displayed_row();
-               auto image_map = ring->image_map;
+               auto image_map = ring->m_image_map;
                auto it = image_map->lower_bound (top_row);
                for (; it != image_map->end (); ++it) {
                        vte::image::image_object *image = it->second;
                        if (image->get_top () > bottom_row)
                                break;
                        if (image->is_freezed ()) {
-                               ring->image_offscreen_resource_counter -= image->resource_size ();
+                               ring->m_image_offscreen_resource_counter -= image->resource_size ();
                                image->thaw ();
-                               ring->image_onscreen_resource_counter += image->resource_size ();
+                               ring->m_image_onscreen_resource_counter += image->resource_size ();
                                _vte_debug_print (VTE_DEBUG_IMAGE,
                                                  "thawn, onscreen: %zu, offscreen: %zu\n",
-                                                 ring->image_onscreen_resource_counter,
-                                                 ring->image_offscreen_resource_counter);
+                                                 ring->m_image_onscreen_resource_counter,
+                                                 ring->m_image_offscreen_resource_counter);
                        }
                        /* Display images */
-                       int x = m_padding.left + image->get_left () * m_char_width;
-                       int y = m_padding.top + (image->get_top () - m_screen->scroll_delta) * m_char_height;
+                       int x = m_padding.left + image->get_left () * m_cell_width;
+                       int y = m_padding.top + (image->get_top () - m_screen->scroll_delta) * m_cell_height;
                        image->paint (cr, x, y);
                }
        }
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index c9dfebc4..1ce4000b 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -5711,7 +5711,7 @@ vte_terminal_set_freezed_image_limit(VteTerminal *terminal, gulong limit)
 gulong
 vte_terminal_get_freezed_image_limit(VteTerminal *terminal)
 {
-        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), NULL);
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), 0);
 
         return IMPL(terminal)->m_freezed_image_limit;
 }
@@ -5724,7 +5724,7 @@ vte_terminal_get_freezed_image_limit(VteTerminal *terminal)
  * Set whether to enable SIXEL graphics feature
  */
 void
-vte_terminal_set_sixel_enabled (VteTerminal *terminal, gboolean enabled)
+vte_terminal_set_sixel_enabled(VteTerminal *terminal, gboolean enabled)
 {
         g_return_if_fail(VTE_IS_TERMINAL(terminal));
 
@@ -5742,9 +5742,9 @@ vte_terminal_set_sixel_enabled (VteTerminal *terminal, gboolean enabled)
  */
 
 gboolean
-vte_terminal_get_sixel_enabled (VteTerminal *terminal)
+vte_terminal_get_sixel_enabled(VteTerminal *terminal)
 {
-        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), NULL);
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), FALSE);
 
         return IMPL(terminal)->m_sixel_enabled;
 }
diff --git a/src/vteseq.cc b/src/vteseq.cc
index f9220e05..4b1d46a1 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -3075,6 +3075,7 @@ Terminal::DECIC(vte::parser::Sequence const& seq)
          */
 }
 
+#if 0
 static void
 vte_sequence_handler_device_control_string (VteTerminalPrivate *that, GValueArray *params)
 {
@@ -3139,9 +3140,10 @@ dispatch:
 end:
        g_free(dcs);
 }
+#endif
 
 void
-VteTerminalPrivate::seq_load_sixel(char const* dcs)
+Terminal::seq_load_sixel(char const* dcs)
 {
        unsigned char *pixels = NULL;
        auto fg = get_color(VTE_DEFAULT_FG);
@@ -3175,13 +3177,13 @@ VteTerminalPrivate::seq_load_sixel(char const* dcs)
        sixel_parser_deinit(&m_sixel_state);
 
        if (m_sixel_display_mode)
-               seq_home_cursor();
+               home_cursor();
 
        /* Append new image to VteRing */
        left = m_screen->cursor.col;
        top = m_screen->cursor.row;
-       width = (m_sixel_state.image.width + m_char_width - 1) / m_char_width;
-       height = (m_sixel_state.image.height + m_char_height - 1) / m_char_height;
+       width = (m_sixel_state.image.width + m_cell_width - 1) / m_cell_width;
+       height = (m_sixel_state.image.height + m_cell_height - 1) / m_cell_height;
        pixelwidth = m_sixel_state.image.width;
        pixelheight = m_sixel_state.image.height;
 
@@ -3202,14 +3204,14 @@ VteTerminalPrivate::seq_load_sixel(char const* dcs)
        free (pixels);
 
        /* create image object */
-       _vte_ring_append_image (m_screen->row_data, surface, pixelwidth, pixelheight, left, top, width, 
height);
+       m_screen->row_data->append_image (surface, pixelwidth, pixelheight, left, top, width, height);
 
        /* Erase characters on the image */
        for (i = 0; i < height; ++i) {
-               seq_erase_characters(width);
+               erase_characters(width);
                if (i == height - 1) {
                        if (m_sixel_scrolls_right)
-                               seq_cursor_forward(width);
+                               move_cursor_forward(width);
                        else
                                cursor_down(true);
                } else {
@@ -3217,7 +3219,7 @@ VteTerminalPrivate::seq_load_sixel(char const* dcs)
                }
        }
        if (m_sixel_display_mode)
-               seq_home_cursor();
+               home_cursor();
 }
 
 void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]