w_grid_alloc: baseline impl

This commit is contained in:
Björn Linse
2021-02-22 15:03:46 +01:00
parent 070e084a64
commit 08ca5207cd
11 changed files with 87 additions and 71 deletions

View File

@@ -2831,8 +2831,8 @@ Array nvim__inspect_cell(Integer grid, Integer row, Integer col, Error *err)
g = &pum_grid; g = &pum_grid;
} else if (grid > 1) { } else if (grid > 1) {
win_T *wp = get_win_by_grid_handle((handle_T)grid); win_T *wp = get_win_by_grid_handle((handle_T)grid);
if (wp != NULL && wp->w_grid.chars != NULL) { if (wp != NULL && wp->w_grid_alloc.chars != NULL) {
g = &wp->w_grid; g = &wp->w_grid_alloc;
} else { } else {
api_set_error(err, kErrorTypeValidation, api_set_error(err, kErrorTypeValidation,
"No grid with the given handle"); "No grid with the given handle");

View File

@@ -1192,10 +1192,10 @@ void aucmd_restbuf(aco_save_T *aco)
win_remove(curwin, NULL); win_remove(curwin, NULL);
handle_unregister_window(curwin); handle_unregister_window(curwin);
if (curwin->w_grid.chars != NULL) { if (curwin->w_grid_alloc.chars != NULL) {
ui_comp_remove_grid(&curwin->w_grid); ui_comp_remove_grid(&curwin->w_grid_alloc);
ui_call_win_hide(curwin->w_grid.handle); ui_call_win_hide(curwin->w_grid_alloc.handle);
grid_free(&curwin->w_grid); grid_free(&curwin->w_grid_alloc);
} }
aucmd_win_used = false; aucmd_win_used = false;

View File

@@ -1409,6 +1409,7 @@ struct window_S {
int w_tagstacklen; // number of tags on stack int w_tagstacklen; // number of tags on stack
ScreenGrid w_grid; // the grid specific to the window ScreenGrid w_grid; // the grid specific to the window
ScreenGrid w_grid_alloc; // the grid specific to the window
bool w_pos_changed; // true if window position changed bool w_pos_changed; // true if window position changed
bool w_floating; ///< whether the window is floating bool w_floating; ///< whether the window is floating
FloatConfig w_float_config; FloatConfig w_float_config;

View File

@@ -1565,7 +1565,7 @@ void edit_putchar(int c, bool highlight)
{ {
int attr; int attr;
if (curwin->w_grid.chars != NULL || default_grid.chars != NULL) { if (curwin->w_grid_alloc.chars != NULL || default_grid.chars != NULL) {
update_topline(curwin); // just in case w_topline isn't valid update_topline(curwin); // just in case w_topline isn't valid
validate_cursor(); validate_cursor();
if (highlight) { if (highlight) {

View File

@@ -35,7 +35,8 @@ typedef int sattr_T;
/// line_wraps[] is an array of boolean flags indicating if the screen line /// line_wraps[] is an array of boolean flags indicating if the screen line
/// wraps to the next line. It can only be true if a window occupies the entire /// wraps to the next line. It can only be true if a window occupies the entire
/// screen width. /// screen width.
typedef struct { typedef struct ScreenGrid ScreenGrid;
struct ScreenGrid {
handle_T handle; handle_T handle;
schar_T *chars; schar_T *chars;
@@ -58,10 +59,13 @@ typedef struct {
// external UI. // external UI.
bool throttled; bool throttled;
// offsets for the grid relative to the global screen. Used by screen.c // TODO(bfredl): maybe physical grids and "views" (i e drawing
// for windows that don't have w_grid->chars etc allocated // specifications) should be two separate types?
// offsets for the grid relative to another grid. Used for grids
// that are views into another, actually allocated grid 'target'
int row_offset; int row_offset;
int col_offset; int col_offset;
ScreenGrid *target;
// whether the compositor should blend the grid with the background grid // whether the compositor should blend the grid with the background grid
bool blending; bool blending;
@@ -89,9 +93,10 @@ typedef struct {
// compositor should momentarily ignore the grid. Used internally when // compositor should momentarily ignore the grid. Used internally when
// moving around grids etc. // moving around grids etc.
bool comp_disabled; bool comp_disabled;
} ScreenGrid; };
#define SCREEN_GRID_INIT { 0, NULL, NULL, NULL, NULL, NULL, 0, 0, false, \ #define SCREEN_GRID_INIT { 0, NULL, NULL, NULL, NULL, NULL, 0, 0, false, \
false, 0, 0, false, true, 0, 0, 0, 0, 0, false } false, 0, 0, NULL, false, true, \
0, 0, 0, 0, 0, false }
#endif // NVIM_GRID_DEFS_H #endif // NVIM_GRID_DEFS_H

View File

@@ -517,6 +517,10 @@ static HlAttrs get_colors_force(int attr)
/// @return the resulting attributes. /// @return the resulting attributes.
int hl_blend_attrs(int back_attr, int front_attr, bool *through) int hl_blend_attrs(int back_attr, int front_attr, bool *through)
{ {
if (front_attr < 0 || back_attr < 0) {
return -1;
}
HlAttrs fattrs = get_colors_force(front_attr); HlAttrs fattrs = get_colors_force(front_attr);
int ratio = fattrs.hl_blend; int ratio = fattrs.hl_blend;
if (ratio <= 0) { if (ratio <= 0) {

View File

@@ -178,6 +178,7 @@ void msg_grid_validate(void)
msg_grid.throttled = false; // don't throttle in 'cmdheight' area msg_grid.throttled = false; // don't throttle in 'cmdheight' area
msg_scrolled_at_flush = msg_scrolled; msg_scrolled_at_flush = msg_scrolled;
msg_grid.focusable = false; msg_grid.focusable = false;
msg_grid_adj.target = &msg_grid;
if (!msg_scrolled) { if (!msg_scrolled) {
msg_grid_set_pos(Rows - p_ch, false); msg_grid_set_pos(Rows - p_ch, false);
} }
@@ -188,6 +189,7 @@ void msg_grid_validate(void)
ui_call_grid_destroy(msg_grid.handle); ui_call_grid_destroy(msg_grid.handle);
msg_grid.throttled = false; msg_grid.throttled = false;
msg_grid_adj.row_offset = 0; msg_grid_adj.row_offset = 0;
msg_grid_adj.target = &default_grid;
redraw_cmdline = true; redraw_cmdline = true;
} else if (msg_grid.chars && !msg_scrolled && msg_grid_pos != Rows - p_ch) { } else if (msg_grid.chars && !msg_scrolled && msg_grid_pos != Rows - p_ch) {
msg_grid_set_pos(Rows - p_ch, false); msg_grid_set_pos(Rows - p_ch, false);

View File

@@ -470,7 +470,7 @@ static win_T *mouse_find_grid_win(int *gridp, int *rowp, int *colp)
*gridp = DEFAULT_GRID_HANDLE; *gridp = DEFAULT_GRID_HANDLE;
} else if (*gridp > 1) { } else if (*gridp > 1) {
win_T *wp = get_win_by_grid_handle(*gridp); win_T *wp = get_win_by_grid_handle(*gridp);
if (wp && wp->w_grid.chars if (wp && wp->w_grid_alloc.chars
&& !(wp->w_floating && !wp->w_float_config.focusable)) { && !(wp->w_floating && !wp->w_float_config.focusable)) {
*rowp = MIN(*rowp, wp->w_grid.Rows-1); *rowp = MIN(*rowp, wp->w_grid.Rows-1);
*colp = MIN(*colp, wp->w_grid.Columns-1); *colp = MIN(*colp, wp->w_grid.Columns-1);
@@ -479,7 +479,7 @@ static win_T *mouse_find_grid_win(int *gridp, int *rowp, int *colp)
} else if (*gridp == 0) { } else if (*gridp == 0) {
ScreenGrid *grid = ui_comp_mouse_focus(*rowp, *colp); ScreenGrid *grid = ui_comp_mouse_focus(*rowp, *colp);
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (&wp->w_grid != grid) { if (&wp->w_grid_alloc != grid) {
continue; continue;
} }
*gridp = grid->handle; *gridp = grid->handle;
@@ -729,7 +729,7 @@ int mouse_check_fold(void)
if (wp && mouse_row >= 0 && mouse_row < Rows if (wp && mouse_row >= 0 && mouse_row < Rows
&& mouse_col >= 0 && mouse_col <= Columns) { && mouse_col >= 0 && mouse_col <= Columns) {
int multigrid = ui_has(kUIMultigrid); int multigrid = ui_has(kUIMultigrid);
ScreenGrid *gp = multigrid ? &wp->w_grid : &default_grid; ScreenGrid *gp = multigrid ? &wp->w_grid_alloc : &default_grid;
int fdc = win_fdccol_count(wp); int fdc = win_fdccol_count(wp);
int row = multigrid && mouse_grid == 0 ? click_row : mouse_row; int row = multigrid && mouse_grid == 0 ? click_row : mouse_row;
int col = multigrid && mouse_grid == 0 ? click_col : mouse_col; int col = multigrid && mouse_grid == 0 ? click_col : mouse_col;

View File

@@ -139,9 +139,8 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed,
cursor_col = curwin->w_wcol; cursor_col = curwin->w_wcol;
} }
pum_anchor_grid = (int)curwin->w_grid.handle; pum_anchor_grid = (int)curwin->w_grid.target->handle;
if (!ui_has(kUIMultigrid)) { if (!ui_has(kUIMultigrid)) {
pum_anchor_grid = (int)default_grid.handle;
pum_win_row += curwin->w_winrow; pum_win_row += curwin->w_winrow;
cursor_col += curwin->w_wincol; cursor_col += curwin->w_wincol;
} }

View File

@@ -232,7 +232,7 @@ void screen_invalidate_highlights(void)
{ {
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
redraw_later(wp, NOT_VALID); redraw_later(wp, NOT_VALID);
wp->w_grid.valid = false; wp->w_grid_alloc.valid = false;
} }
} }
@@ -582,8 +582,8 @@ int update_screen(int type)
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_redr_type == CLEAR && wp->w_floating && wp->w_grid.chars) { if (wp->w_redr_type == CLEAR && wp->w_floating && wp->w_grid_alloc.chars) {
grid_invalidate(&wp->w_grid); grid_invalidate(&wp->w_grid_alloc);
wp->w_redr_type = NOT_VALID; wp->w_redr_type = NOT_VALID;
} }
@@ -4404,14 +4404,10 @@ void draw_virt_text(buf_T *buf, int *end_col, int max_col)
/// screen positions. /// screen positions.
void screen_adjust_grid(ScreenGrid **grid, int *row_off, int *col_off) void screen_adjust_grid(ScreenGrid **grid, int *row_off, int *col_off)
{ {
if (!(*grid)->chars && *grid != &default_grid) { if ((*grid)->target) {
*row_off += (*grid)->row_offset; *row_off += (*grid)->row_offset;
*col_off += (*grid)->col_offset; *col_off += (*grid)->col_offset;
if (*grid == &msg_grid_adj && msg_grid.chars) { *grid = (*grid)->target;
*grid = &msg_grid;
} else {
*grid = &default_grid;
}
} }
} }
@@ -6143,12 +6139,13 @@ void check_for_delay(int check_msg_scroll)
void win_grid_alloc(win_T *wp) void win_grid_alloc(win_T *wp)
{ {
ScreenGrid *grid = &wp->w_grid; ScreenGrid *grid = &wp->w_grid;
ScreenGrid *grid_allocated = &wp->w_grid_alloc;
int rows = wp->w_height_inner; int rows = wp->w_height_inner;
int cols = wp->w_width_inner; int cols = wp->w_width_inner;
bool want_allocation = ui_has(kUIMultigrid) || wp->w_floating; bool want_allocation = ui_has(kUIMultigrid) || wp->w_floating;
bool has_allocation = (grid->chars != NULL); bool has_allocation = (grid_allocated->chars != NULL);
if (grid->Rows != rows) { if (grid->Rows != rows) {
wp->w_lines_valid = 0; wp->w_lines_valid = 0;
@@ -6156,36 +6153,45 @@ void win_grid_alloc(win_T *wp)
wp->w_lines = xcalloc(rows+1, sizeof(wline_T)); wp->w_lines = xcalloc(rows+1, sizeof(wline_T));
} }
int total_rows = rows, total_cols = cols;
int was_resized = false; int was_resized = false;
if ((has_allocation != want_allocation) if (want_allocation && (!has_allocation
|| grid->Rows != rows || grid_allocated->Rows != total_rows
|| grid->Columns != cols) { || grid_allocated->Columns != total_cols)) {
if (want_allocation) { grid_alloc(grid_allocated, total_rows, total_cols, wp->w_grid_alloc.valid, false);
grid_alloc(grid, rows, cols, wp->w_grid.valid, false); grid_allocated->valid = true;
grid->valid = true;
} else {
// Single grid mode, all rendering will be redirected to default_grid.
// Only keep track of the size and offset of the window.
grid_free(grid);
grid->Rows = rows;
grid->Columns = cols;
grid->valid = false;
}
was_resized = true; was_resized = true;
} else if (want_allocation && has_allocation && !wp->w_grid.valid) { } else if (!want_allocation && has_allocation) {
grid_invalidate(grid); // Single grid mode, all rendering will be redirected to default_grid.
grid->valid = true; // Only keep track of the size and offset of the window.
grid_free(grid_allocated);
grid_allocated->valid = false;
was_resized = true;
} else if (want_allocation && has_allocation && !wp->w_grid_alloc.valid) {
grid_invalidate(grid_allocated);
grid_allocated->valid = true;
} }
grid->row_offset = wp->w_winrow; grid->Rows = rows;
grid->col_offset = wp->w_wincol; grid->Columns = cols;
if (want_allocation) {
grid->target = grid_allocated;
grid->row_offset = 0;
grid->col_offset = 0;
} else {
grid->target = &default_grid;
grid->row_offset = wp->w_winrow;
grid->col_offset = wp->w_wincol;
}
// send grid resize event if: // send grid resize event if:
// - a grid was just resized // - a grid was just resized
// - screen_resize was called and all grid sizes must be sent // - screen_resize was called and all grid sizes must be sent
// - the UI wants multigrid event (necessary) // - the UI wants multigrid event (necessary)
if ((send_grid_resize || was_resized) && want_allocation) { if ((send_grid_resize || was_resized) && want_allocation) {
ui_call_grid_resize(grid->handle, grid->Columns, grid->Rows); ui_call_grid_resize(grid_allocated->handle, grid_allocated->Columns, grid_allocated->Rows);
} }
} }
@@ -7531,7 +7537,7 @@ void win_new_shellsize(void)
win_T *get_win_by_grid_handle(handle_T handle) win_T *get_win_by_grid_handle(handle_T handle)
{ {
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_grid.handle == handle) { if (wp->w_grid_alloc.handle == handle) {
return wp; return wp;
} }
} }

View File

@@ -713,7 +713,7 @@ int win_fdccol_count(win_T *wp)
void ui_ext_win_position(win_T *wp) void ui_ext_win_position(win_T *wp)
{ {
if (!wp->w_floating) { if (!wp->w_floating) {
ui_call_win_pos(wp->w_grid.handle, wp->handle, wp->w_winrow, ui_call_win_pos(wp->w_grid_alloc.handle, wp->handle, wp->w_winrow,
wp->w_wincol, wp->w_width, wp->w_height); wp->w_wincol, wp->w_width, wp->w_height);
return; return;
} }
@@ -743,7 +743,7 @@ void ui_ext_win_position(win_T *wp)
} }
if (ui_has(kUIMultigrid)) { if (ui_has(kUIMultigrid)) {
String anchor = cstr_to_string(float_anchor_str[c.anchor]); String anchor = cstr_to_string(float_anchor_str[c.anchor]);
ui_call_win_float_pos(wp->w_grid.handle, wp->handle, anchor, grid->handle, ui_call_win_float_pos(wp->w_grid_alloc.handle, wp->handle, anchor, grid->handle,
row, col, c.focusable); row, col, c.focusable);
} else { } else {
// TODO(bfredl): ideally, compositor should work like any multigrid UI // TODO(bfredl): ideally, compositor should work like any multigrid UI
@@ -759,17 +759,17 @@ void ui_ext_win_position(win_T *wp)
wp->w_wincol = comp_col; wp->w_wincol = comp_col;
bool valid = (wp->w_redr_type == 0); bool valid = (wp->w_redr_type == 0);
bool on_top = (curwin == wp) || !curwin->w_floating; bool on_top = (curwin == wp) || !curwin->w_floating;
ui_comp_put_grid(&wp->w_grid, comp_row, comp_col, wp->w_height, ui_comp_put_grid(&wp->w_grid_alloc, comp_row, comp_col, wp->w_height,
wp->w_width, valid, on_top); wp->w_width, valid, on_top);
ui_check_cursor_grid(wp->w_grid.handle); ui_check_cursor_grid(wp->w_grid_alloc.handle);
wp->w_grid.focusable = wp->w_float_config.focusable; wp->w_grid_alloc.focusable = wp->w_float_config.focusable;
if (!valid) { if (!valid) {
wp->w_grid.valid = false; wp->w_grid_alloc.valid = false;
redraw_later(wp, NOT_VALID); redraw_later(wp, NOT_VALID);
} }
} }
} else { } else {
ui_call_win_external_pos(wp->w_grid.handle, wp->handle); ui_call_win_external_pos(wp->w_grid_alloc.handle, wp->handle);
} }
} }
@@ -784,7 +784,7 @@ void ui_ext_win_viewport(win_T *wp)
// interact with incomplete final line? Diff filler lines? // interact with incomplete final line? Diff filler lines?
botline = wp->w_buffer->b_ml.ml_line_count; botline = wp->w_buffer->b_ml.ml_line_count;
} }
ui_call_win_viewport(wp->w_grid.handle, wp->handle, wp->w_topline-1, ui_call_win_viewport(wp->w_grid_alloc.handle, wp->handle, wp->w_topline-1,
botline, wp->w_cursor.lnum-1, wp->w_cursor.col); botline, wp->w_cursor.lnum-1, wp->w_cursor.col);
wp->w_viewport_invalid = false; wp->w_viewport_invalid = false;
} }
@@ -1953,12 +1953,12 @@ static void win_totop(int size, int flags)
} }
if (curwin->w_floating) { if (curwin->w_floating) {
ui_comp_remove_grid(&curwin->w_grid); ui_comp_remove_grid(&curwin->w_grid_alloc);
if (ui_has(kUIMultigrid)) { if (ui_has(kUIMultigrid)) {
curwin->w_pos_changed = true; curwin->w_pos_changed = true;
} else { } else {
// No longer a float, a non-multigrid UI shouldn't draw it as such // No longer a float, a non-multigrid UI shouldn't draw it as such
ui_call_win_hide(curwin->w_grid.handle); ui_call_win_hide(curwin->w_grid_alloc.handle);
win_free_grid(curwin, false); win_free_grid(curwin, false);
} }
} else { } else {
@@ -2581,11 +2581,11 @@ int win_close(win_T *win, bool free_buf)
bool was_floating = win->w_floating; bool was_floating = win->w_floating;
if (ui_has(kUIMultigrid)) { if (ui_has(kUIMultigrid)) {
ui_call_win_close(win->w_grid.handle); ui_call_win_close(win->w_grid_alloc.handle);
} }
if (win->w_floating) { if (win->w_floating) {
ui_comp_remove_grid(&win->w_grid); ui_comp_remove_grid(&win->w_grid_alloc);
if (win->w_float_config.external) { if (win->w_float_config.external) {
for (tabpage_T *tp = first_tabpage; tp != NULL; tp = tp->tp_next) { for (tabpage_T *tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
if (tp == curtab) { if (tp == curtab) {
@@ -4131,7 +4131,7 @@ static void tabpage_check_windows(tabpage_T *old_curtab)
win_remove(wp, old_curtab); win_remove(wp, old_curtab);
win_append(lastwin_nofloating(), wp); win_append(lastwin_nofloating(), wp);
} else { } else {
ui_comp_remove_grid(&wp->w_grid); ui_comp_remove_grid(&wp->w_grid_alloc);
} }
} }
wp->w_pos_changed = true; wp->w_pos_changed = true;
@@ -4726,7 +4726,7 @@ static win_T *win_alloc(win_T *after, int hidden)
new_wp->handle = ++last_win_id; new_wp->handle = ++last_win_id;
handle_register_window(new_wp); handle_register_window(new_wp);
grid_assign_handle(&new_wp->w_grid); grid_assign_handle(&new_wp->w_grid_alloc);
// Init w: variables. // Init w: variables.
new_wp->w_vars = tv_dict_alloc(); new_wp->w_vars = tv_dict_alloc();
@@ -4850,15 +4850,14 @@ win_free (
void win_free_grid(win_T *wp, bool reinit) void win_free_grid(win_T *wp, bool reinit)
{ {
if (wp->w_grid.handle != 0 && ui_has(kUIMultigrid)) { if (wp->w_grid_alloc.handle != 0 && ui_has(kUIMultigrid)) {
ui_call_grid_destroy(wp->w_grid.handle); ui_call_grid_destroy(wp->w_grid_alloc.handle);
wp->w_grid.handle = 0;
} }
grid_free(&wp->w_grid); grid_free(&wp->w_grid_alloc);
if (reinit) { if (reinit) {
// if a float is turned into a split and back into a float, the grid // if a float is turned into a split and back into a float, the grid
// data structure will be reused // data structure will be reused
memset(&wp->w_grid, 0, sizeof(wp->w_grid)); memset(&wp->w_grid_alloc, 0, sizeof(wp->w_grid_alloc));
} }
} }
@@ -7099,11 +7098,11 @@ void get_framelayout(const frame_T *fr, list_T *l, bool outer)
void win_ui_flush(void) void win_ui_flush(void)
{ {
FOR_ALL_TAB_WINDOWS(tp, wp) { FOR_ALL_TAB_WINDOWS(tp, wp) {
if (wp->w_pos_changed && wp->w_grid.chars != NULL) { if (wp->w_pos_changed && wp->w_grid_alloc.chars != NULL) {
if (tp == curtab) { if (tp == curtab) {
ui_ext_win_position(wp); ui_ext_win_position(wp);
} else { } else {
ui_call_win_hide(wp->w_grid.handle); ui_call_win_hide(wp->w_grid_alloc.handle);
} }
wp->w_pos_changed = false; wp->w_pos_changed = false;
} }