[vte] widget: Cache the allocation



commit b7f1c94646a84795740d8b59deb7086936190b60
Author: Christian Persch <chpe gnome org>
Date:   Tue Dec 15 20:38:41 2015 +0100

    widget: Cache the allocation

 src/vte.cc         |   34 ++++++++++++++++------------------
 src/vteinternal.hh |    6 ++++++
 src/vtetypes.hh    |    2 +-
 3 files changed, 23 insertions(+), 19 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index caa2401..91848ac 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -272,7 +272,7 @@ VteTerminalPrivate::reset_default_attributes()
 inline vte::view::coord_t
 VteTerminalPrivate::usable_height_px() const
 {
-        return gtk_widget_get_allocated_height(m_widget) - m_padding.top - m_padding.bottom;
+        return get_allocated_height() - m_padding.top - m_padding.bottom;
 }
 
 //FIXMEchpe this function is bad
@@ -367,7 +367,6 @@ VteTerminalPrivate::invalidate_cells(vte::grid::column_t column_start,
                                      int n_rows)
 {
        cairo_rectangle_int_t rect;
-       GtkAllocation allocation;
 
        if (G_UNLIKELY (!widget_realized()))
                 return;
@@ -392,7 +391,7 @@ VteTerminalPrivate::invalidate_cells(vte::grid::column_t column_start,
                return;
        }
 
-        gtk_widget_get_allocation (m_widget, &allocation);
+        auto allocation = get_allocated_rect();
 
        /* Convert the column and row start and end to pixel values
         * by multiplying by the size of a character cell.
@@ -477,7 +476,6 @@ void
 VteTerminalPrivate::invalidate_all()
 {
        cairo_rectangle_int_t rect;
-       GtkAllocation allocation;
 
        if (G_UNLIKELY (!widget_realized()))
                 return;
@@ -489,7 +487,7 @@ VteTerminalPrivate::invalidate_all()
        _vte_debug_print (VTE_DEBUG_WORK, "*");
        _vte_debug_print (VTE_DEBUG_UPDATES, "Invalidating all.\n");
 
-       gtk_widget_get_allocation (m_widget, &allocation);
+        auto allocation = get_allocated_rect();
 
        /* replace invalid regions with one covering the whole terminal */
        reset_update_regions (m_terminal);
@@ -5868,9 +5866,7 @@ void
 VteTerminalPrivate::match_hilite(long x,
                                  long y)
 {
-       GtkAllocation allocation;
-
-       gtk_widget_get_allocation(m_widget, &allocation);
+        auto allocation = get_allocated_rect();
 
        /* if the cursor is not above a cell, skip */
        if (x < 0 || x > allocation.width
@@ -8018,6 +8014,11 @@ VteTerminalPrivate::VteTerminalPrivate(VteTerminal *t) :
         // FIXMEchpe temporary workaround until all functions have been converted to members
         m_terminal->pvt = this;
 
+        /* Inits allocation to 1x1 @ -1,-1 */
+        cairo_rectangle_int_t allocation;
+        gtk_widget_get_allocation(m_widget, &allocation);
+        set_allocated_rect(allocation);
+
        int i;
        GdkDisplay *display;
 
@@ -8235,7 +8236,6 @@ void
 VteTerminalPrivate::widget_size_allocate(GtkAllocation *allocation)
 {
        glong width, height;
-       GtkAllocation current_allocation;
        gboolean repaint, update_scrollback;
 
        _vte_debug_print(VTE_DEBUG_LIFECYCLE,
@@ -8254,7 +8254,7 @@ VteTerminalPrivate::widget_size_allocate(GtkAllocation *allocation)
                        allocation->width, allocation->height,
                        width, height);
 
-       gtk_widget_get_allocation(m_widget, &current_allocation);
+        auto current_allocation = get_allocated_rect();
 
        repaint = current_allocation.width != allocation->width
                        || current_allocation.height != allocation->height;
@@ -8262,6 +8262,7 @@ VteTerminalPrivate::widget_size_allocate(GtkAllocation *allocation)
 
        /* Set our allocation to match the structure. */
        gtk_widget_set_allocation(m_widget, allocation);
+        set_allocated_rect(*allocation);
 
        if (width != m_column_count
                        || height != m_row_count
@@ -8599,12 +8600,11 @@ VteTerminalPrivate::widget_realize()
 {
        GdkWindow *window;
        GdkWindowAttr attributes;
-       GtkAllocation allocation;
        guint attributes_mask = 0;
 
        _vte_debug_print(VTE_DEBUG_LIFECYCLE, "vte_terminal_realize()\n");
 
-       gtk_widget_get_allocation (m_widget, &allocation);
+        auto allocation = get_allocated_rect();
 
        /* Create the stock cursors. */
        m_mouse_cursor_visible = TRUE;
@@ -9511,9 +9511,8 @@ VteTerminalPrivate::expand_cairo_region(cairo_region_t *region,
         vte::grid::row_t row, row_stop;
         vte::grid::column_t col, col_stop;
        cairo_rectangle_int_t rect;
-       GtkAllocation allocation;
 
-       gtk_widget_get_allocation(m_widget, &allocation);
+        auto allocation = get_allocated_rect();
 
        /* increase the paint by one pixel on all sides to force the
         * inclusion of neighbouring cells */
@@ -9557,9 +9556,8 @@ VteTerminalPrivate::paint_area(GdkRectangle const* area)
 {
         vte::grid::row_t row, row_stop;
         vte::grid::column_t col, col_stop;
-       GtkAllocation allocation;
 
-       gtk_widget_get_allocation(m_widget, &allocation);
+        auto allocation = get_allocated_rect();
 
         row = pixel_to_row(MAX(0, area->y - m_padding.top));
         /* Both the value given by MIN() and row_stop are exclusive.
@@ -9821,8 +9819,8 @@ VteTerminalPrivate::widget_draw(cairo_t *cr)
         if (region == NULL)
                 return;
 
-        allocated_width = gtk_widget_get_allocated_width(m_widget);
-        allocated_height = gtk_widget_get_allocated_height(m_widget);
+        allocated_width = get_allocated_width();
+        allocated_height = get_allocated_height();
 
        /* Designate the start of the drawing operation and clear the area. */
        _vte_draw_set_cairo(m_draw, cr);
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 6e34dea..0b11d22 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -496,7 +496,13 @@ public:
         VteCursorBlinkMode decscusr_cursor_blink();
         VteCursorShape decscusr_cursor_shape();
 
+        cairo_rectangle_int_t m_allocated_rect;
+        void set_allocated_rect(cairo_rectangle_int_t const& r) { m_allocated_rect = r; }
+
         inline bool widget_realized() const { return gtk_widget_get_realized(m_widget); }
+        inline cairo_rectangle_int_t const& get_allocated_rect() const { return m_allocated_rect; }
+        inline vte::view::coord_t get_allocated_width() const { return m_allocated_rect.width; }
+        inline vte::view::coord_t get_allocated_height() const { return m_allocated_rect.height; }
 
         void widget_paste(GdkAtom board);
         void widget_copy(VteSelection sel);
diff --git a/src/vtetypes.hh b/src/vtetypes.hh
index a0e6299..cba4f3e 100644
--- a/src/vtetypes.hh
+++ b/src/vtetypes.hh
@@ -114,7 +114,7 @@ namespace view {
         public:
                 coord_t x;
                 coord_t y;
-};
+        };
 
 } /* namespace view */
 


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