Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7cf7c0a

Browse filesBrowse files
authored
Merge pull request #9575 from bfredl/redrawdebug
ui: implement better redrawdebug for the compositor
2 parents 48a5897 + 2c2f160 commit 7cf7c0a
Copy full SHA for 7cf7c0a

File tree

Expand file treeCollapse file tree

10 files changed

+215
-8
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+215
-8
lines changed

‎runtime/doc/options.txt

Copy file name to clipboardExpand all lines: runtime/doc/options.txt
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4552,6 +4552,25 @@ A jump table for the options with a short description can be found at |Q_op|.
45524552
set for the newly edited buffer.
45534553
See 'modifiable' for disallowing changes to the buffer.
45544554

4555+
*'redrawdebug'* *'rdb'*
4556+
'redrawdebug' 'rdb' string (default '')
4557+
global
4558+
Flags to change the way redrawing works, for debugging purposes.
4559+
Most useful with 'writedelay' set to some reasonable value.
4560+
Supports the following flags:
4561+
compositor Indicate what redraws come from the compositor
4562+
by briefly flashing the redrawn regions in colors
4563+
indicating the redraw type. These are the highlight
4564+
groups used (and their default colors):
4565+
RedrawDebugNormal gui=reverse normal redraw passed through
4566+
RedrawDebugClear guibg=Yellow clear event passed through
4567+
RedrawDebugComposed guibg=Green redraw event modified by the
4568+
compositor (due to
4569+
overlapping grids, etc)
4570+
RedrawDebugRecompose guibg=Red redraw generated by the
4571+
compositor itself, due to a
4572+
grid being moved or deleted.
4573+
45554574
*'redrawtime'* *'rdt'*
45564575
'redrawtime' 'rdt' number (default 2000)
45574576
global

‎src/nvim/main.c

Copy file name to clipboardExpand all lines: src/nvim/main.c
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "nvim/strings.h"
5555
#include "nvim/syntax.h"
5656
#include "nvim/ui.h"
57+
#include "nvim/ui_compositor.h"
5758
#include "nvim/version.h"
5859
#include "nvim/window.h"
5960
#include "nvim/shada.h"
@@ -220,6 +221,7 @@ void early_init(void)
220221
set_lang_var(); // set v:lang and v:ctype
221222

222223
init_signs();
224+
ui_comp_syn_init();
223225
}
224226

225227
#ifdef MAKE_LIB

‎src/nvim/option.c

Copy file name to clipboardExpand all lines: src/nvim/option.c
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,7 @@ static void didset_options(void)
21912191
(void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, true);
21922192
(void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, true);
21932193
(void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, true);
2194+
(void)opt_strings_flags(p_rdb, p_rdb_values, &rdb_flags, true);
21942195
(void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, false);
21952196
(void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, true);
21962197
(void)opt_strings_flags(p_wop, p_wop_values, &wop_flags, true);
@@ -2650,6 +2651,10 @@ did_set_string_option(
26502651
if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, true) != OK) {
26512652
errmsg = e_invarg;
26522653
}
2654+
} else if (varp == &p_rdb) { // 'redrawdebug'
2655+
if (opt_strings_flags(p_rdb, p_rdb_values, &rdb_flags, true) != OK) {
2656+
errmsg = e_invarg;
2657+
}
26532658
} else if (varp == &p_sbo) { // 'scrollopt'
26542659
if (check_opt_strings(p_sbo, p_scbopt_values, true) != OK) {
26552660
errmsg = e_invarg;

‎src/nvim/option_defs.h

Copy file name to clipboardExpand all lines: src/nvim/option_defs.h
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,13 @@ EXTERN char_u *p_pm; // 'patchmode'
511511
EXTERN char_u *p_path; // 'path'
512512
EXTERN char_u *p_cdpath; // 'cdpath'
513513
EXTERN long p_pyx; // 'pyxversion'
514+
EXTERN char_u *p_rdb; // 'redrawdebug'
515+
EXTERN unsigned rdb_flags;
516+
# ifdef IN_OPTION_C
517+
static char *(p_rdb_values[]) = { "compositor", NULL };
518+
# endif
519+
# define RDB_COMPOSITOR 0x001
520+
514521
EXTERN long p_rdt; // 'redrawtime'
515522
EXTERN int p_remap; // 'remap'
516523
EXTERN long p_re; // 'regexpengine'

‎src/nvim/options.lua

Copy file name to clipboardExpand all lines: src/nvim/options.lua
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,13 @@ return {
18471847
varname='p_ro',
18481848
defaults={if_true={vi=false}}
18491849
},
1850+
{
1851+
full_name='redrawdebug', abbreviation='rdb',
1852+
type='string', list='onecomma', scope={'global'},
1853+
vi_def=true,
1854+
varname='p_rdb',
1855+
defaults={if_true={vi=''}}
1856+
},
18501857
{
18511858
full_name='redrawtime', abbreviation='rdt',
18521859
type='number', scope={'global'},

‎src/nvim/syntax.c

Copy file name to clipboardExpand all lines: src/nvim/syntax.c
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5970,6 +5970,10 @@ static const char *highlight_init_both[] = {
59705970
"default link Whitespace NonText",
59715971
"default link MsgSeparator StatusLine",
59725972
"default link NormalFloat Pmenu",
5973+
"RedrawDebugNormal cterm=reverse gui=reverse",
5974+
"RedrawDebugClear ctermbg=Yellow guibg=Yellow",
5975+
"RedrawDebugComposed ctermbg=Green guibg=Green",
5976+
"RedrawDebugRecompose ctermbg=Red guibg=Red",
59735977
NULL
59745978
};
59755979

‎src/nvim/ui.c

Copy file name to clipboardExpand all lines: src/nvim/ui.c
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,15 @@ void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol,
341341
flags, (const schar_T *)grid->chars + off,
342342
(const sattr_T *)grid->attrs + off);
343343

344-
if (p_wd) { // 'writedelay': flush & delay each time.
345-
int old_row = cursor_row, old_col = cursor_col;
346-
handle_T old_grid = cursor_grid_handle;
344+
// 'writedelay': flush & delay each time.
345+
if (p_wd && !(rdb_flags & RDB_COMPOSITOR)) {
347346
// If 'writedelay' is active, set the cursor to indicate what was drawn.
348-
ui_grid_cursor_goto(grid->handle, row, MIN(clearcol, (int)Columns-1));
349-
ui_flush();
347+
ui_call_grid_cursor_goto(grid->handle, row,
348+
MIN(clearcol, (int)grid->Columns-1));
349+
ui_call_flush();
350350
uint64_t wd = (uint64_t)labs(p_wd);
351351
os_microdelay(wd * 1000u, true);
352-
ui_grid_cursor_goto(old_grid, old_row, old_col);
352+
pending_cursor_update = true; // restore the cursor later
353353
}
354354
}
355355

‎src/nvim/ui_compositor.c

Copy file name to clipboardExpand all lines: src/nvim/ui_compositor.c
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ static bool valid_screen = true;
4949
static bool msg_scroll_mode = false;
5050
static int msg_first_invalid = 0;
5151

52+
static int dbghl_normal, dbghl_clear, dbghl_composed, dbghl_recompose;
53+
5254
void ui_comp_init(void)
5355
{
5456
if (compositor != NULL) {
@@ -81,6 +83,13 @@ void ui_comp_init(void)
8183
ui_attach_impl(compositor);
8284
}
8385

86+
void ui_comp_syn_init(void)
87+
{
88+
dbghl_normal = syn_check_group((char_u *)S_LEN("RedrawDebugNormal"));
89+
dbghl_clear = syn_check_group((char_u *)S_LEN("RedrawDebugClear"));
90+
dbghl_composed = syn_check_group((char_u *)S_LEN("RedrawDebugComposed"));
91+
dbghl_recompose = syn_check_group((char_u *)S_LEN("RedrawDebugRecompose"));
92+
}
8493

8594
void ui_comp_attach(UI *ui)
8695
{
@@ -385,9 +394,42 @@ static void compose_line(Integer row, Integer startcol, Integer endcol,
385394
(const sattr_T *)attrbuf+skipstart);
386395
}
387396

397+
static void compose_debug(Integer startrow, Integer endrow, Integer startcol,
398+
Integer endcol, int syn_id, bool delay)
399+
{
400+
if (!(rdb_flags & RDB_COMPOSITOR)) {
401+
return;
402+
}
403+
404+
endrow = MIN(endrow, default_grid.Rows);
405+
endcol = MIN(endcol, default_grid.Columns);
406+
int attr = syn_id2attr(syn_id);
407+
408+
for (int row = (int)startrow; row < endrow; row++) {
409+
ui_composed_call_raw_line(1, row, startcol, startcol, endcol, attr, false,
410+
(const schar_T *)linebuf,
411+
(const sattr_T *)attrbuf);
412+
}
413+
414+
415+
if (delay) {
416+
debug_delay(endrow-startrow);
417+
}
418+
}
419+
420+
static void debug_delay(Integer lines)
421+
{
422+
ui_call_flush();
423+
uint64_t wd = (uint64_t)labs(p_wd);
424+
uint64_t factor = (uint64_t)MAX(MIN(lines, 5), 1);
425+
os_microdelay(factor * wd * 1000u, true);
426+
}
427+
428+
388429
static void compose_area(Integer startrow, Integer endrow,
389430
Integer startcol, Integer endcol)
390431
{
432+
compose_debug(startrow, endrow, startcol, endcol, dbghl_recompose, true);
391433
endrow = MIN(endrow, default_grid.Rows);
392434
endcol = MIN(endcol, default_grid.Columns);
393435
if (endcol <= startcol) {
@@ -432,8 +474,11 @@ static void ui_comp_raw_line(UI *ui, Integer grid, Integer row,
432474
if (flags & kLineFlagInvalid
433475
|| kv_size(layers) > curgrid->comp_index+1
434476
|| curgrid->blending) {
477+
compose_debug(row, row+1, startcol, clearcol, dbghl_composed, true);
435478
compose_line(row, startcol, clearcol, flags);
436479
} else {
480+
compose_debug(row, row+1, startcol, endcol, dbghl_normal, false);
481+
compose_debug(row, row+1, endcol, clearcol, dbghl_clear, true);
437482
ui_composed_call_raw_line(1, row, startcol, endcol, clearcol, clearattr,
438483
flags, chunk, attrs);
439484
}
@@ -493,6 +538,9 @@ static void ui_comp_grid_scroll(UI *ui, Integer grid, Integer top,
493538
} else {
494539
msg_first_invalid = MIN(msg_first_invalid, (int)top);
495540
ui_composed_call_grid_scroll(1, top, bot, left, right, rows, cols);
541+
if (rdb_flags & RDB_COMPOSITOR) {
542+
debug_delay(2);
543+
}
496544
}
497545
}
498546

‎test/functional/ui/cursor_spec.lua

Copy file name to clipboardExpand all lines: test/functional/ui/cursor_spec.lua
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ describe('ui/cursor', function()
216216
if m.blinkwait then m.blinkwait = 700 end
217217
end
218218
if m.hl_id then
219-
m.hl_id = 50
219+
m.hl_id = 54
220220
m.attr = {background = Screen.colors.DarkGray}
221221
end
222-
if m.id_lm then m.id_lm = 51 end
222+
if m.id_lm then m.id_lm = 55 end
223223
end
224224

225225
-- Assert the new expectation.

‎test/functional/ui/float_spec.lua

Copy file name to clipboardExpand all lines: test/functional/ui/float_spec.lua
+115Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,121 @@ describe('floating windows', function()
172172
end
173173
end)
174174

175+
it('draws correctly with redrawdebug=compositor', function()
176+
-- NB: we do not test that it produces the "correct" debug info
177+
-- (as it is intermediate only, and is allowed to change by internal
178+
-- refactors). Only check that it doesn't cause permanent glitches,
179+
-- or something.
180+
command("set redrawdebug=compositor")
181+
command("set wd=1")
182+
local buf = meths.create_buf(false,false)
183+
local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5})
184+
local expected_pos = {
185+
[3]={{id=1001}, 'NW', 1, 2, 5, true},
186+
}
187+
188+
if multigrid then
189+
screen:expect{grid=[[
190+
## grid 1
191+
[2:----------------------------------------]|
192+
[2:----------------------------------------]|
193+
[2:----------------------------------------]|
194+
[2:----------------------------------------]|
195+
[2:----------------------------------------]|
196+
[2:----------------------------------------]|
197+
|
198+
## grid 2
199+
^ |
200+
{0:~ }|
201+
{0:~ }|
202+
{0:~ }|
203+
{0:~ }|
204+
{0:~ }|
205+
## grid 3
206+
{1: }|
207+
{2:~ }|
208+
]], float_pos=expected_pos}
209+
else
210+
screen:expect([[
211+
^ |
212+
{0:~ }|
213+
{0:~ }{1: }{0: }|
214+
{0:~ }{2:~ }{0: }|
215+
{0:~ }|
216+
{0:~ }|
217+
|
218+
]])
219+
end
220+
221+
222+
meths.win_set_config(win, {relative='editor', row=0, col=10})
223+
expected_pos[3][4] = 0
224+
expected_pos[3][5] = 10
225+
if multigrid then
226+
screen:expect{grid=[[
227+
## grid 1
228+
[2:----------------------------------------]|
229+
[2:----------------------------------------]|
230+
[2:----------------------------------------]|
231+
[2:----------------------------------------]|
232+
[2:----------------------------------------]|
233+
[2:----------------------------------------]|
234+
|
235+
## grid 2
236+
^ |
237+
{0:~ }|
238+
{0:~ }|
239+
{0:~ }|
240+
{0:~ }|
241+
{0:~ }|
242+
## grid 3
243+
{1: }|
244+
{2:~ }|
245+
]], float_pos=expected_pos}
246+
else
247+
screen:expect([[
248+
^ {1: } |
249+
{0:~ }{2:~ }{0: }|
250+
{0:~ }|
251+
{0:~ }|
252+
{0:~ }|
253+
{0:~ }|
254+
|
255+
]])
256+
end
257+
258+
meths.win_close(win, false)
259+
if multigrid then
260+
screen:expect([[
261+
## grid 1
262+
[2:----------------------------------------]|
263+
[2:----------------------------------------]|
264+
[2:----------------------------------------]|
265+
[2:----------------------------------------]|
266+
[2:----------------------------------------]|
267+
[2:----------------------------------------]|
268+
|
269+
## grid 2
270+
^ |
271+
{0:~ }|
272+
{0:~ }|
273+
{0:~ }|
274+
{0:~ }|
275+
{0:~ }|
276+
]])
277+
else
278+
screen:expect([[
279+
^ |
280+
{0:~ }|
281+
{0:~ }|
282+
{0:~ }|
283+
{0:~ }|
284+
{0:~ }|
285+
|
286+
]])
287+
end
288+
end)
289+
175290
it('return their configuration', function()
176291
local buf = meths.create_buf(false, false)
177292
local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=3, col=5})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.