static schar_T *current_ScreenLine;
#ifdef FEAT_TEXT_PROP
+static void may_update_popup_mask(int type);
static void update_popups(void);
#endif
static void win_update(win_T *wp);
}
#ifdef FEAT_TEXT_PROP
- // Update popup_mask if needed.
- type = may_update_popup_mask(type);
+ // Update popup_mask if needed. This may set w_redraw_top and w_redraw_bot
+ // in some windows.
+ may_update_popup_mask(type);
#endif
updating_screen = TRUE;
}
#ifdef FEAT_TEXT_PROP
+
/*
* Update "popup_mask" if needed.
* Also recomputes the popup size and positions.
* Also updates "popup_visible".
- * If more redrawing is needed than "type_arg" a higher value is returned.
+ * Also marks window lines for redrawing.
*/
- int
-may_update_popup_mask(int type_arg)
+ static void
+may_update_popup_mask(int type)
{
- int type = type_arg;
win_T *wp;
+ short *mask;
+ int line, col;
if (popup_mask_tab != curtab)
popup_mask_refresh = TRUE;
if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer))
popup_mask_refresh = TRUE;
if (!popup_mask_refresh)
- return type;
+ return;
}
+ // Need to update the mask, something has changed.
popup_mask_refresh = FALSE;
popup_mask_tab = curtab;
-
popup_visible = FALSE;
- vim_memset(popup_mask, 0, screen_Rows * screen_Columns * sizeof(short));
+
+ // If redrawing everything, just update "popup_mask".
+ // If redrawing only what is needed, update "popup_mask_next" and then
+ // compare with "popup_mask" to see what changed.
+ if (type >= SOME_VALID)
+ mask = popup_mask;
+ else
+ mask = popup_mask_next;
+ vim_memset(mask, 0, screen_Rows * screen_Columns * sizeof(short));
// Find the window with the lowest zindex that hasn't been handled yet,
// so that the window with a higher zindex overwrites the value in
popup_reset_handled();
while ((wp = find_next_popup(TRUE)) != NULL)
{
- int top_off, bot_off;
- int left_off, right_off;
- short *p;
- int line, col;
+ int height_extra, width_extra;
popup_visible = TRUE;
if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer))
popup_adjust_position(wp);
- // the position and size are for the inside, add the padding and
+ // the width and height are for the inside, add the padding and
// border
- top_off = wp->w_popup_padding[0] + wp->w_popup_border[0];
- bot_off = wp->w_popup_padding[2] + wp->w_popup_border[2];
- left_off = wp->w_popup_padding[3] + wp->w_popup_border[3];
- right_off = wp->w_popup_padding[1] + wp->w_popup_border[1];
+ height_extra = wp->w_popup_padding[0] + wp->w_popup_border[0]
+ + wp->w_popup_padding[2] + wp->w_popup_border[2];
+ width_extra = wp->w_popup_padding[3] + wp->w_popup_border[3]
+ + wp->w_popup_padding[1] + wp->w_popup_border[1];
- for (line = wp->w_winrow + top_off;
- line < wp->w_winrow + wp->w_height + bot_off
+ for (line = wp->w_winrow;
+ line < wp->w_winrow + wp->w_height + height_extra
&& line < screen_Rows; ++line)
- for (col = wp->w_wincol + left_off;
- col < wp->w_wincol + wp->w_width + right_off
+ for (col = wp->w_wincol;
+ col < wp->w_wincol + wp->w_width + width_extra
&& col < screen_Columns; ++col)
+ mask[line * screen_Columns + col] = wp->w_zindex;
+ }
+
+ // Only check which lines are to be updated if not already
+ // updating all lines.
+ if (mask == popup_mask_next)
+ for (line = 0; line < screen_Rows; ++line)
+ {
+ int col_done = 0;
+
+ for (col = 0; col < screen_Columns; ++col)
{
- p = popup_mask + line * screen_Columns + col;
- if (*p != wp->w_zindex)
+ int off = line * screen_Columns + col;
+
+ if (popup_mask[off] != popup_mask_next[off])
{
- *p = wp->w_zindex;
- type = NOT_VALID;
+ popup_mask[off] = popup_mask_next[off];
+
+ // The screen position "line" / "col" needs to be redrawn.
+ // Figure out what window that is and update w_redraw_top
+ // and w_redr_bot. Only needs to be done for each window
+ // line.
+ if (col >= col_done)
+ {
+ linenr_T lnum;
+ int line_cp = line;
+ int col_cp = col;
+
+ // find the window where the row is in
+ wp = mouse_find_win(&line_cp, &col_cp);
+ if (wp != NULL)
+ {
+ if (line_cp >= wp->w_height)
+ // In (or below) status line
+ wp->w_redr_status = TRUE;
+ // compute the position in the buffer line from the
+ // position on the screen
+ else if (mouse_comp_pos(wp, &line_cp, &col_cp,
+ &lnum))
+ // past bottom
+ wp->w_redr_status = TRUE;
+ else
+ redrawWinline(wp, lnum);
+
+ // This line is going to be redrawn, no need to
+ // check until the right side of the window.
+ col_done = wp->w_wincol + wp->w_width - 1;
+ }
+ }
}
}
- }
-
- return type;
+ }
}
/*
short *new_TabPageIdxs;
#ifdef FEAT_TEXT_PROP
short *new_popup_mask;
+ short *new_popup_mask_next;
#endif
tabpage_T *tp;
static int entered = FALSE; /* avoid recursiveness */
new_TabPageIdxs = LALLOC_MULT(short, Columns);
#ifdef FEAT_TEXT_PROP
new_popup_mask = LALLOC_MULT(short, Rows * Columns);
+ new_popup_mask_next = LALLOC_MULT(short, Rows * Columns);
#endif
FOR_ALL_TAB_WINDOWS(tp, wp)
|| new_TabPageIdxs == NULL
#ifdef FEAT_TEXT_PROP
|| new_popup_mask == NULL
+ || new_popup_mask_next == NULL
#endif
|| outofmem)
{
VIM_CLEAR(new_TabPageIdxs);
#ifdef FEAT_TEXT_PROP
VIM_CLEAR(new_popup_mask);
+ VIM_CLEAR(new_popup_mask_next);
#endif
}
else
TabPageIdxs = new_TabPageIdxs;
#ifdef FEAT_TEXT_PROP
popup_mask = new_popup_mask;
+ popup_mask_next = new_popup_mask_next;
vim_memset(popup_mask, 0, Rows * Columns * sizeof(short));
popup_mask_refresh = TRUE;
#endif
VIM_CLEAR(TabPageIdxs);
#ifdef FEAT_TEXT_PROP
VIM_CLEAR(popup_mask);
+ VIM_CLEAR(popup_mask_next);
#endif
}
}
#ifdef FEAT_TEXT_PROP
- // this doesn't work when tere are popups visible
+ // this doesn't work when there are popups visible
if (popup_visible)
return FAIL;
#endif
--- /dev/null
+" Use this script to measure the redrawing performance when a popup is being
+" displayed. Usage with gcc:
+" cd src
+" # Edit Makefile to uncomment PROFILE_CFLAGS and PROFILE_LIBS
+" make reconfig
+" ./vim --clean -S testdir/popupbounce.vim main.c
+" gprof vim gmon.out | vim -
+
+" using line contination
+set nocp
+
+" don't switch screens when quitting, so we can read the frames/sec
+set t_te=
+
+let winid = popup_create(['line1', 'line2', 'line3', 'line4'], {
+ \ 'line' : 1,
+ \ 'col' : 1,
+ \ 'zindex' : 101,
+ \ })
+redraw
+
+let start = reltime()
+let framecount = 0
+
+let line = 1.0
+let col = 1
+let downwards = 1
+let col_inc = 1
+let initial_speed = 0.2
+let speed = initial_speed
+let accel = 1.1
+let time = 0.1
+
+let countdown = 0
+
+while 1
+ if downwards
+ let speed += time * accel
+ let line += speed
+ else
+ let speed -= time * accel
+ let line -= speed
+ endif
+
+ if line + 3 >= &lines
+ let downwards = 0
+ let speed = speed * 0.8
+ let line = &lines - 3
+ endif
+ if !downwards && speed < 1.0
+ let downwards = 1
+ let speed = initial_speed
+ if line + 4 > &lines && countdown == 0
+ let countdown = 50
+ endif
+ endif
+
+ let col += col_inc
+ if col + 4 >= &columns
+ let col_inc = -1
+ elseif col <= 1
+ let col_inc = 1
+ endif
+
+ call popup_move(winid, {'line': float2nr(line), 'col': col})
+ redraw
+ let framecount += 1
+ if countdown > 0
+ let countdown -= 1
+ if countdown == 0
+ break
+ endif
+ endif
+
+endwhile
+
+let elapsed = reltimefloat(reltime(start))
+echomsg framecount .. ' frames in ' .. string(elapsed) .. ' seconds, ' .. string(framecount / elapsed) .. ' frames/sec'
+
+qa