Lines Matching refs:vb
50 #define VTBUF_LOCK(vb) mtx_lock_spin(&(vb)->vb_lock) argument
51 #define VTBUF_UNLOCK(vb) mtx_unlock_spin(&(vb)->vb_lock) argument
60 static int vtbuf_htw(const struct vt_buf *vb, int row);
61 static int vtbuf_wth(const struct vt_buf *vb, int row);
74 vthistory_seek(struct vt_buf *vb, int offset, int whence) in vthistory_seek() argument
79 if ((vb->vb_flags & VBF_SCROLL) == 0) { in vthistory_seek()
80 if (vb->vb_roffset != vb->vb_curroffset) { in vthistory_seek()
81 vb->vb_roffset = vb->vb_curroffset; in vthistory_seek()
88 bottom = vb->vb_curroffset; in vthistory_seek()
89 top = (vb->vb_flags & VBF_HISTORY_FULL) ? in vthistory_seek()
90 bottom + vb->vb_scr_size.tp_row - vb->vb_history_size : in vthistory_seek()
105 roffset = vb->vb_roffset; in vthistory_seek()
106 if (roffset >= bottom + vb->vb_scr_size.tp_row) in vthistory_seek()
107 roffset -= vb->vb_history_size; in vthistory_seek()
114 roffset = vb->vb_history_size + roffset; in vthistory_seek()
119 roffset = vb->vb_curroffset; in vthistory_seek()
123 diff = vb->vb_roffset != roffset; in vthistory_seek()
124 vb->vb_roffset = roffset; in vthistory_seek()
130 vthistory_addlines(struct vt_buf *vb, int offset) in vthistory_addlines() argument
136 vb->vb_curroffset += offset; in vthistory_addlines()
137 if (vb->vb_curroffset + vb->vb_scr_size.tp_row >= vb->vb_history_size) { in vthistory_addlines()
138 vb->vb_flags |= VBF_HISTORY_FULL; in vthistory_addlines()
139 vb->vb_curroffset %= vb->vb_history_size; in vthistory_addlines()
141 if ((vb->vb_flags & VBF_SCROLL) == 0) { in vthistory_addlines()
142 vb->vb_roffset = vb->vb_curroffset; in vthistory_addlines()
146 sz = vb->vb_history_size; in vthistory_addlines()
147 cur = vb->vb_roffset + vb->vb_scr_size.tp_row + sz - 1; in vthistory_addlines()
148 if (vtbuf_in_this_range(cur, vb->vb_mark_start.tp_row, cur + offset, sz) || in vthistory_addlines()
149 vtbuf_in_this_range(cur, vb->vb_mark_end.tp_row, cur + offset, sz)) { in vthistory_addlines()
151 vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row; in vthistory_addlines()
152 vb->vb_mark_start.tp_col = vb->vb_mark_end.tp_col; in vthistory_addlines()
158 vthistory_getpos(const struct vt_buf *vb, unsigned int *offset) in vthistory_getpos() argument
161 *offset = vb->vb_roffset; in vthistory_getpos()
167 vtbuf_htw(const struct vt_buf *vb, int row) in vtbuf_htw() argument
176 return ((row - vb->vb_roffset + vb->vb_history_size) % in vtbuf_htw()
177 vb->vb_history_size); in vtbuf_htw()
182 vtbuf_wth(const struct vt_buf *vb, int row) in vtbuf_wth() argument
185 return ((vb->vb_roffset + row) % vb->vb_history_size); in vtbuf_wth()
212 vtbuf_iscursor(const struct vt_buf *vb, int row, int col) in vtbuf_iscursor() argument
218 if ((vb->vb_flags & (VBF_CURSOR|VBF_SCROLL)) == VBF_CURSOR && in vtbuf_iscursor()
219 (vb->vb_cursor.tp_row == row) && (vb->vb_cursor.tp_col == col)) in vtbuf_iscursor()
224 if (vb->vb_mark_start.tp_col == vb->vb_mark_end.tp_col && in vtbuf_iscursor()
225 vb->vb_mark_start.tp_row == vb->vb_mark_end.tp_row) in vtbuf_iscursor()
228 sc = vb->vb_mark_start.tp_col; in vtbuf_iscursor()
229 sr = vb->vb_mark_start.tp_row; in vtbuf_iscursor()
230 ec = vb->vb_mark_end.tp_col; in vtbuf_iscursor()
231 er = vb->vb_mark_end.tp_row; in vtbuf_iscursor()
238 sz = vb->vb_history_size; in vtbuf_iscursor()
240 row = vtbuf_wth(vb, row); in vtbuf_iscursor()
257 vtbuf_lock(struct vt_buf *vb) in vtbuf_lock() argument
260 VTBUF_LOCK(vb); in vtbuf_lock()
264 vtbuf_unlock(struct vt_buf *vb) in vtbuf_unlock() argument
267 VTBUF_UNLOCK(vb); in vtbuf_unlock()
271 vtbuf_dirty(struct vt_buf *vb, const term_rect_t *area) in vtbuf_dirty() argument
274 if (vb->vb_dirtyrect.tr_begin.tp_row > area->tr_begin.tp_row) in vtbuf_dirty()
275 vb->vb_dirtyrect.tr_begin.tp_row = area->tr_begin.tp_row; in vtbuf_dirty()
276 if (vb->vb_dirtyrect.tr_begin.tp_col > area->tr_begin.tp_col) in vtbuf_dirty()
277 vb->vb_dirtyrect.tr_begin.tp_col = area->tr_begin.tp_col; in vtbuf_dirty()
278 if (vb->vb_dirtyrect.tr_end.tp_row < area->tr_end.tp_row) in vtbuf_dirty()
279 vb->vb_dirtyrect.tr_end.tp_row = area->tr_end.tp_row; in vtbuf_dirty()
280 if (vb->vb_dirtyrect.tr_end.tp_col < area->tr_end.tp_col) in vtbuf_dirty()
281 vb->vb_dirtyrect.tr_end.tp_col = area->tr_end.tp_col; in vtbuf_dirty()
285 vtbuf_dirty_cell(struct vt_buf *vb, const term_pos_t *p) in vtbuf_dirty_cell() argument
292 vtbuf_dirty(vb, &area); in vtbuf_dirty_cell()
296 vtbuf_make_undirty(struct vt_buf *vb) in vtbuf_make_undirty() argument
299 vb->vb_dirtyrect.tr_begin = vb->vb_scr_size; in vtbuf_make_undirty()
300 vb->vb_dirtyrect.tr_end.tp_row = vb->vb_dirtyrect.tr_end.tp_col = 0; in vtbuf_make_undirty()
304 vtbuf_undirty(struct vt_buf *vb, term_rect_t *r) in vtbuf_undirty() argument
307 *r = vb->vb_dirtyrect; in vtbuf_undirty()
308 vtbuf_make_undirty(vb); in vtbuf_undirty()
312 vtbuf_copy(struct vt_buf *vb, const term_rect_t *r, const term_pos_t *p2) in vtbuf_copy() argument
319 KASSERT(r->tr_begin.tp_row < vb->vb_scr_size.tp_row, in vtbuf_copy()
321 r->tr_begin.tp_row, vb->vb_scr_size.tp_row)); in vtbuf_copy()
322 KASSERT(r->tr_begin.tp_col < vb->vb_scr_size.tp_col, in vtbuf_copy()
324 r->tr_begin.tp_col, vb->vb_scr_size.tp_col)); in vtbuf_copy()
326 KASSERT(r->tr_end.tp_row <= vb->vb_scr_size.tp_row, in vtbuf_copy()
328 r->tr_end.tp_row, vb->vb_scr_size.tp_row)); in vtbuf_copy()
329 KASSERT(r->tr_end.tp_col <= vb->vb_scr_size.tp_col, in vtbuf_copy()
331 r->tr_end.tp_col, vb->vb_scr_size.tp_col)); in vtbuf_copy()
333 KASSERT(p2->tp_row < vb->vb_scr_size.tp_row, in vtbuf_copy()
335 p2->tp_row, vb->vb_scr_size.tp_row)); in vtbuf_copy()
336 KASSERT(p2->tp_col < vb->vb_scr_size.tp_col, in vtbuf_copy()
338 p2->tp_col, vb->vb_scr_size.tp_col)); in vtbuf_copy()
344 r->tr_end.tp_col == vb->vb_scr_size.tp_col && /* Full row. */ in vtbuf_copy()
345 (rows + rdiff) == vb->vb_scr_size.tp_row && /* Whole screen. */ in vtbuf_copy()
347 vthistory_addlines(vb, rdiff); in vtbuf_copy()
353 &VTBUF_FIELD(vb, p2->tp_row + pr, p2->tp_col), in vtbuf_copy()
354 &VTBUF_FIELD(vb, p1->tp_row + pr, p1->tp_col), in vtbuf_copy()
360 &VTBUF_FIELD(vb, p2->tp_row + pr, p2->tp_col), in vtbuf_copy()
361 &VTBUF_FIELD(vb, p1->tp_row + pr, p1->tp_col), in vtbuf_copy()
366 area.tr_end.tp_row = MIN(p2->tp_row + rows, vb->vb_scr_size.tp_row); in vtbuf_copy()
367 area.tr_end.tp_col = MIN(p2->tp_col + cols, vb->vb_scr_size.tp_col); in vtbuf_copy()
368 vtbuf_dirty(vb, &area); in vtbuf_copy()
372 vtbuf_do_fill(struct vt_buf *vb, const term_rect_t *r, term_char_t c) in vtbuf_do_fill() argument
378 row = vb->vb_rows[(vb->vb_curroffset + pr) % in vtbuf_do_fill()
379 VTBUF_MAX_HEIGHT(vb)]; in vtbuf_do_fill()
387 vtbuf_fill(struct vt_buf *vb, const term_rect_t *r, term_char_t c) in vtbuf_fill() argument
390 KASSERT(r->tr_begin.tp_row < vb->vb_scr_size.tp_row, in vtbuf_fill()
392 r->tr_begin.tp_row, vb->vb_scr_size.tp_row)); in vtbuf_fill()
393 KASSERT(r->tr_begin.tp_col < vb->vb_scr_size.tp_col, in vtbuf_fill()
395 r->tr_begin.tp_col, vb->vb_scr_size.tp_col)); in vtbuf_fill()
397 KASSERT(r->tr_end.tp_row <= vb->vb_scr_size.tp_row, in vtbuf_fill()
399 r->tr_end.tp_row, vb->vb_scr_size.tp_row)); in vtbuf_fill()
400 KASSERT(r->tr_end.tp_col <= vb->vb_scr_size.tp_col, in vtbuf_fill()
402 r->tr_end.tp_col, vb->vb_scr_size.tp_col)); in vtbuf_fill()
404 vtbuf_do_fill(vb, r, c); in vtbuf_fill()
405 vtbuf_dirty(vb, r); in vtbuf_fill()
409 vtbuf_init_rows(struct vt_buf *vb) in vtbuf_init_rows() argument
413 vb->vb_history_size = MAX(vb->vb_history_size, vb->vb_scr_size.tp_row); in vtbuf_init_rows()
415 for (r = 0; r < vb->vb_history_size; r++) in vtbuf_init_rows()
416 vb->vb_rows[r] = &vb->vb_buffer[r * vb->vb_scr_size.tp_col]; in vtbuf_init_rows()
420 vtbuf_init_early(struct vt_buf *vb) in vtbuf_init_early() argument
424 vb->vb_flags |= VBF_CURSOR; in vtbuf_init_early()
425 vb->vb_roffset = 0; in vtbuf_init_early()
426 vb->vb_curroffset = 0; in vtbuf_init_early()
427 vb->vb_mark_start.tp_row = 0; in vtbuf_init_early()
428 vb->vb_mark_start.tp_col = 0; in vtbuf_init_early()
429 vb->vb_mark_end.tp_row = 0; in vtbuf_init_early()
430 vb->vb_mark_end.tp_col = 0; in vtbuf_init_early()
432 vtbuf_init_rows(vb); in vtbuf_init_early()
434 rect.tr_end.tp_col = vb->vb_scr_size.tp_col; in vtbuf_init_early()
435 rect.tr_end.tp_row = vb->vb_history_size; in vtbuf_init_early()
436 vtbuf_do_fill(vb, &rect, VTBUF_SPACE_CHAR(TERMINAL_NORM_ATTR)); in vtbuf_init_early()
437 vtbuf_make_undirty(vb); in vtbuf_init_early()
438 if ((vb->vb_flags & VBF_MTX_INIT) == 0) { in vtbuf_init_early()
439 mtx_init(&vb->vb_lock, "vtbuf", NULL, MTX_SPIN); in vtbuf_init_early()
440 vb->vb_flags |= VBF_MTX_INIT; in vtbuf_init_early()
445 vtbuf_init(struct vt_buf *vb, const term_pos_t *p) in vtbuf_init() argument
449 vb->vb_scr_size = *p; in vtbuf_init()
450 vb->vb_history_size = VBF_DEFAULT_HISTORY_SIZE; in vtbuf_init()
452 if ((vb->vb_flags & VBF_STATIC) == 0) { in vtbuf_init()
453 sz = vb->vb_history_size * p->tp_col * sizeof(term_char_t); in vtbuf_init()
454 vb->vb_buffer = malloc(sz, M_VTBUF, M_WAITOK | M_ZERO); in vtbuf_init()
456 sz = vb->vb_history_size * sizeof(term_char_t *); in vtbuf_init()
457 vb->vb_rows = malloc(sz, M_VTBUF, M_WAITOK | M_ZERO); in vtbuf_init()
460 vtbuf_init_early(vb); in vtbuf_init()
464 vtbuf_sethistory_size(struct vt_buf *vb, unsigned int size) in vtbuf_sethistory_size() argument
469 p.tp_row = vb->vb_scr_size.tp_row; in vtbuf_sethistory_size()
470 p.tp_col = vb->vb_scr_size.tp_col; in vtbuf_sethistory_size()
471 vtbuf_grow(vb, &p, size); in vtbuf_sethistory_size()
475 vtbuf_grow(struct vt_buf *vb, const term_pos_t *p, unsigned int history_size) in vtbuf_grow() argument
491 VTBUF_LOCK(vb); in vtbuf_grow()
492 old = vb->vb_flags & VBF_STATIC ? NULL : vb->vb_buffer; in vtbuf_grow()
493 oldrows = vb->vb_flags & VBF_STATIC ? NULL : vb->vb_rows; in vtbuf_grow()
494 copyrows = vb->vb_rows; in vtbuf_grow()
496 w = vb->vb_scr_size.tp_col; in vtbuf_grow()
497 h = vb->vb_scr_size.tp_row; in vtbuf_grow()
498 old_history_size = vb->vb_history_size; in vtbuf_grow()
499 history_full = vb->vb_flags & VBF_HISTORY_FULL || in vtbuf_grow()
500 vb->vb_curroffset + h >= history_size; in vtbuf_grow()
502 vb->vb_history_size = history_size; in vtbuf_grow()
503 vb->vb_buffer = new; in vtbuf_grow()
504 vb->vb_rows = rows; in vtbuf_grow()
505 vb->vb_flags &= ~VBF_STATIC; in vtbuf_grow()
506 vb->vb_scr_size = *p; in vtbuf_grow()
507 vtbuf_init_rows(vb); in vtbuf_grow()
527 (vb->vb_curroffset + h + r) % in vtbuf_grow()
559 vb->vb_flags &= ~VBF_HISTORY_FULL; in vtbuf_grow()
572 vb->vb_curroffset = old_history_size - h; in vtbuf_grow()
589 (vb->vb_curroffset + h + r + in vtbuf_grow()
609 vb->vb_curroffset = history_size - h; in vtbuf_grow()
610 vb->vb_flags |= VBF_HISTORY_FULL; in vtbuf_grow()
614 vb->vb_roffset = vb->vb_curroffset; in vtbuf_grow()
617 if (vb->vb_cursor.tp_col > p->tp_col - 1) in vtbuf_grow()
622 vb->vb_cursor.tp_col = p->tp_col - 1; in vtbuf_grow()
624 if (vb->vb_curroffset > 0 || vb->vb_cursor.tp_row > p->tp_row - 1) in vtbuf_grow()
626 vb->vb_cursor.tp_row = p->tp_row - 1; in vtbuf_grow()
628 VTBUF_UNLOCK(vb); in vtbuf_grow()
636 vtbuf_putchar(struct vt_buf *vb, const term_pos_t *p, term_char_t c) in vtbuf_putchar() argument
640 KASSERT(p->tp_row < vb->vb_scr_size.tp_row, in vtbuf_putchar()
642 p->tp_row, vb->vb_scr_size.tp_row)); in vtbuf_putchar()
643 KASSERT(p->tp_col < vb->vb_scr_size.tp_col, in vtbuf_putchar()
645 p->tp_col, vb->vb_scr_size.tp_col)); in vtbuf_putchar()
647 row = vb->vb_rows[(vb->vb_curroffset + p->tp_row) % in vtbuf_putchar()
648 VTBUF_MAX_HEIGHT(vb)]; in vtbuf_putchar()
651 vtbuf_dirty_cell(vb, p); in vtbuf_putchar()
656 vtbuf_cursor_position(struct vt_buf *vb, const term_pos_t *p) in vtbuf_cursor_position() argument
658 if (vb->vb_flags & VBF_CURSOR) { in vtbuf_cursor_position()
659 vtbuf_dirty_cell(vb, &vb->vb_cursor); in vtbuf_cursor_position()
660 vb->vb_cursor = *p; in vtbuf_cursor_position()
661 vtbuf_dirty_cell(vb, &vb->vb_cursor); in vtbuf_cursor_position()
663 vb->vb_cursor = *p; in vtbuf_cursor_position()
669 vtbuf_flush_mark(struct vt_buf *vb) in vtbuf_flush_mark() argument
675 if ((vb->vb_mark_start.tp_col != vb->vb_mark_end.tp_col) || in vtbuf_flush_mark()
676 (vb->vb_mark_start.tp_row != vb->vb_mark_end.tp_row)) { in vtbuf_flush_mark()
678 s = vtbuf_htw(vb, vb->vb_mark_start.tp_row); in vtbuf_flush_mark()
679 e = vtbuf_htw(vb, vb->vb_mark_end.tp_row); in vtbuf_flush_mark()
684 area.tr_end.tp_col = vb->vb_scr_size.tp_col; in vtbuf_flush_mark()
687 VTBUF_LOCK(vb); in vtbuf_flush_mark()
688 vtbuf_dirty(vb, &area); in vtbuf_flush_mark()
689 VTBUF_UNLOCK(vb); in vtbuf_flush_mark()
694 vtbuf_get_marked_len(struct vt_buf *vb) in vtbuf_get_marked_len() argument
700 if (POS_INDEX(vtbuf_htw(vb, vb->vb_mark_start.tp_row), in vtbuf_get_marked_len()
701 vb->vb_mark_start.tp_col) > in vtbuf_get_marked_len()
702 POS_INDEX(vtbuf_htw(vb, vb->vb_mark_end.tp_row), in vtbuf_get_marked_len()
703 vb->vb_mark_end.tp_col)) { in vtbuf_get_marked_len()
704 POS_COPY(e, vb->vb_mark_start); in vtbuf_get_marked_len()
705 POS_COPY(s, vb->vb_mark_end); in vtbuf_get_marked_len()
707 POS_COPY(s, vb->vb_mark_start); in vtbuf_get_marked_len()
708 POS_COPY(e, vb->vb_mark_end); in vtbuf_get_marked_len()
711 si = s.tp_row * vb->vb_scr_size.tp_col + s.tp_col; in vtbuf_get_marked_len()
712 ei = e.tp_row * vb->vb_scr_size.tp_col + e.tp_col; in vtbuf_get_marked_len()
721 vtbuf_extract_marked(struct vt_buf *vb, term_char_t *buf, int sz) in vtbuf_extract_marked() argument
727 if (POS_INDEX(vtbuf_htw(vb, vb->vb_mark_start.tp_row), in vtbuf_extract_marked()
728 vb->vb_mark_start.tp_col) > in vtbuf_extract_marked()
729 POS_INDEX(vtbuf_htw(vb, vb->vb_mark_end.tp_row), in vtbuf_extract_marked()
730 vb->vb_mark_end.tp_col)) { in vtbuf_extract_marked()
731 POS_COPY(e, vb->vb_mark_start); in vtbuf_extract_marked()
732 POS_COPY(s, vb->vb_mark_end); in vtbuf_extract_marked()
734 POS_COPY(s, vb->vb_mark_start); in vtbuf_extract_marked()
735 POS_COPY(e, vb->vb_mark_end); in vtbuf_extract_marked()
741 ce = (r == e.tp_row)?e.tp_col:vb->vb_scr_size.tp_col; in vtbuf_extract_marked()
743 buf[i++] = vb->vb_rows[r][c]; in vtbuf_extract_marked()
754 vtbuf_set_mark(struct vt_buf *vb, int type, int col, int row) in vtbuf_set_mark() argument
761 if (vb->vb_mark_last != VTB_MARK_MOVE) in vtbuf_set_mark()
766 vtbuf_flush_mark(vb); /* Clean old mark. */ in vtbuf_set_mark()
767 vb->vb_mark_end.tp_col = col; in vtbuf_set_mark()
768 vb->vb_mark_end.tp_row = vtbuf_wth(vb, row); in vtbuf_set_mark()
771 vtbuf_flush_mark(vb); /* Clean old mark. */ in vtbuf_set_mark()
772 vb->vb_mark_start.tp_col = col; in vtbuf_set_mark()
773 vb->vb_mark_start.tp_row = vtbuf_wth(vb, row); in vtbuf_set_mark()
775 vb->vb_mark_end.tp_col = col; in vtbuf_set_mark()
776 vb->vb_mark_end.tp_row = vtbuf_wth(vb, row); in vtbuf_set_mark()
779 vtbuf_flush_mark(vb); /* Clean old mark. */ in vtbuf_set_mark()
780 vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row = in vtbuf_set_mark()
781 vtbuf_wth(vb, row); in vtbuf_set_mark()
782 r = vb->vb_rows[vb->vb_mark_start.tp_row]; in vtbuf_set_mark()
785 vb->vb_mark_start.tp_col = i + 1; in vtbuf_set_mark()
789 for (i = col; i < vb->vb_scr_size.tp_col; i ++) { in vtbuf_set_mark()
791 vb->vb_mark_end.tp_col = i; in vtbuf_set_mark()
795 if (vb->vb_mark_start.tp_col > vb->vb_mark_end.tp_col) in vtbuf_set_mark()
796 vb->vb_mark_start.tp_col = vb->vb_mark_end.tp_col; in vtbuf_set_mark()
799 vtbuf_flush_mark(vb); /* Clean old mark. */ in vtbuf_set_mark()
800 vb->vb_mark_start.tp_col = 0; in vtbuf_set_mark()
801 vb->vb_mark_end.tp_col = vb->vb_scr_size.tp_col; in vtbuf_set_mark()
802 vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row = in vtbuf_set_mark()
803 vtbuf_wth(vb, row); in vtbuf_set_mark()
806 vb->vb_mark_last = type; in vtbuf_set_mark()
813 vb->vb_mark_last = type; in vtbuf_set_mark()
815 vtbuf_flush_mark(vb); in vtbuf_set_mark()
821 vtbuf_cursor_visibility(struct vt_buf *vb, int yes) in vtbuf_cursor_visibility() argument
825 oflags = vb->vb_flags; in vtbuf_cursor_visibility()
827 vb->vb_flags |= VBF_CURSOR; in vtbuf_cursor_visibility()
829 vb->vb_flags &= ~VBF_CURSOR; in vtbuf_cursor_visibility()
830 nflags = vb->vb_flags; in vtbuf_cursor_visibility()
833 vtbuf_dirty_cell(vb, &vb->vb_cursor); in vtbuf_cursor_visibility()
837 vtbuf_scroll_mode(struct vt_buf *vb, int yes) in vtbuf_scroll_mode() argument
841 VTBUF_LOCK(vb); in vtbuf_scroll_mode()
842 oflags = vb->vb_flags; in vtbuf_scroll_mode()
844 vb->vb_flags |= VBF_SCROLL; in vtbuf_scroll_mode()
846 vb->vb_flags &= ~VBF_SCROLL; in vtbuf_scroll_mode()
847 nflags = vb->vb_flags; in vtbuf_scroll_mode()
850 vtbuf_dirty_cell(vb, &vb->vb_cursor); in vtbuf_scroll_mode()
851 VTBUF_UNLOCK(vb); in vtbuf_scroll_mode()